<?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>xaml ninja &#187; Xaml</title>
	<atom:link href="http://blogs.xamlninja.com/category/xaml/feed" rel="self" type="application/rss+xml" />
	<link>http://blogs.xamlninja.com</link>
	<description>xaml ninja moves</description>
	<lastBuildDate>Tue, 10 Jan 2012 19:46:49 +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>Metro Controls &#8211; Jump Viewer</title>
		<link>http://blogs.xamlninja.com/xaml/metro-controls-jump-viewer</link>
		<comments>http://blogs.xamlninja.com/xaml/metro-controls-jump-viewer#comments</comments>
		<pubDate>Fri, 30 Sep 2011 18:23:49 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[Metro]]></category>
		<category><![CDATA[Xaml]]></category>
		<category><![CDATA[winrt]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/?p=740</guid>
		<description><![CDATA[After an amazing week at //Build, I&#8217;ve been busy playing with the new controls, which I have to say are fantastic! Ollie and I know the pain first hand when it comes to building a Silverlight TUI (Touch User Interface) it&#8217;s not a great story and IMHO the controls are not ready. I may still [...]]]></description>
			<content:encoded><![CDATA[<p>After an amazing week at //Build, I&#8217;ve been busy playing with the new controls, which I have to say are fantastic! <a href="http://awkwardcoder.blogspot.com/" target="_blank">Ollie </a>and I know the pain first hand when it comes to building a Silverlight TUI (Touch User Interface) it&#8217;s not a great story and IMHO the controls are not ready. I may still post my thoughts on this experience, I&#8217;ve been holding back as I really don&#8217;t want to be dragged into the Silverlight is DEAD! debacle and this post could be taken in this way, however it will give you context around why we are so pleased that there is a new story and that one is awesome. But while I think about posting my experiences of building TUI on slates running Win 7, I&#8217;ve been putting together notes on the controls and thought that these may be beneficial to others so my objectives are to walk through some of the new controls and peel the layers like an onion. So, we can then go deep on certain topics.</p>
<p>So without further ado please say a big HELLO! to the Jump Viewer which is currently my favourite control. The interactions are stunning and performance is awesome! Before I start to dig in we should take a look at the finished control. The first screen shot is of the Jump Viewer when it first loads up in its zoomed in state and the second screen shot is taken when we peform an inwards pinch gesture which zooms out and the semantic zoom kicks in replacing the view with higher level details so that we can easily jump to another position in the Grid.</p>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2011/09/JumpViewer1.png" rel="shadowbox[sbpost-740];player=img;"><img class="alignleft size-large wp-image-742" title="JumpViewer1" src="http://blogs.xamlninja.com/wp-content/uploads/2011/09/JumpViewer1-1024x574.png" alt="" width="1024" height="574" /></a></p>
<p>&nbsp;</p>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2011/09/JumpViewer2.png" rel="shadowbox[sbpost-740];player=img;"><img class="alignleft size-full wp-image-743" title="JumpViewer2" src="http://blogs.xamlninja.com/wp-content/uploads/2011/09/JumpViewer2.png" alt="" width="813" height="763" /></a></p>
<p>&nbsp;</p>
<p>Note:- there are some anti-aliasing issues that happen periodically, not sure why this happens but I will update the post when I know more.</p>
<p>&nbsp;</p>
<p>For more background reading on semantic zoom check out <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465319%28v=vs.85%29.aspx" target="_blank">the guidelines for semantic zoom</a> and also the <a href="http://code.msdn.microsoft.com/windowsapps/Semantic-zoom-sample-2ca01adf" target="_blank">sample in the SDK</a>.</p>
<p>What I really like about the Jump Viewer is that it uses composition, allowing you to simply wrap up other controls that you may have used previously in order to deliver an immersive experience when interacting with the visualised data. In order to build a better understanding of the control we need to look at the Xaml. Lets start by concentrating on the JumpView which is the part of the control that is activated when we zoom out.</p>
<p>I have added my notes into the Xaml and hopefully this is a better way of groking the Xaml rather than snippets and dialogue, this way you can copy and paste the Xaml into your app and retain the notes.</p>
<pre class="brush: xml">

 &lt;!--
The jump view is the visual effect when we use semantic zoom the pinch-in gesture
The grid view items panel is set to a wrapgrid
Which renders a list of category names
--&gt;
&lt;JumpViewer x:Name=&quot;jumpViewer&quot;
        Grid.Row=&quot;1&quot;
        Margin=&quot;120,0,0,0&quot;&gt;
        &lt;!--
        The jump viewer jump view
        --&gt;
        &lt;JumpViewer.JumpView&gt;
                &lt;GridView Foreground=&quot;White&quot;&gt;
                &lt;GridView.ItemTemplate&gt;
                &lt;!--
                Data template used to visualise what we want to display when zoomed out
                In our case we are showing some group text
                --&gt;
                &lt;DataTemplate&gt;
                        &lt;TextBlock Text=&quot;{Binding Name}&quot;
                        FontFamily=&quot;{StaticResource SemiBoldContentFontFamily}&quot;
                        FontSize=&quot;{StaticResource HeaderLargeFontSize}&quot;
                        Foreground=&quot;{StaticResource PageForegroundBrush}&quot; /&gt;
                &lt;/DataTemplate&gt;
                &lt;/GridView.ItemTemplate&gt;
                &lt;GridView.ItemsPanel&gt;
                        &lt;ItemsPanelTemplate&gt;
                            &lt;!--
                                Positions child elements sequentially from left to right or top to bottom.
                                When elements extend beyond the container edge, elements are positioned in the next row or column.
                                You can change the Maximum rows or columns to change the visual layout when zoomed out
                            --&gt;
                            &lt;WrapGrid ItemWidth=&quot;114&quot;
                                      ItemHeight=&quot;114&quot;
                                      MaximumRowsOrColumns=&quot;6&quot;
                                      VerticalChildrenAlignment=&quot;Center&quot; /&gt;
                        &lt;/ItemsPanelTemplate&gt;
                &lt;/GridView.ItemsPanel&gt;
                &lt;!--
                Note when we change the item container style the target type is ListViewItem not GridViewItem
                --&gt;
                &lt;GridView.ItemContainerStyle&gt;
                    &lt;Style TargetType=&quot;ListViewItem&quot;&gt;
                        &lt;Setter Property=&quot;Margin&quot;
                                Value=&quot;6&quot; /&gt;
                        &lt;Setter Property=&quot;Padding&quot;
                                Value=&quot;12&quot; /&gt;
                        &lt;Setter Property=&quot;BorderBrush&quot;
                                Value=&quot;{StaticResource PageForegroundBrush}&quot; /&gt;
                        &lt;Setter Property=&quot;BorderThickness&quot;
                                Value=&quot;1&quot; /&gt;
                        &lt;Setter Property=&quot;HorizontalContentAlignment&quot;
                                Value=&quot;Center&quot; /&gt;
                        &lt;Setter Property=&quot;VerticalContentAlignment&quot;
                                Value=&quot;Center&quot; /&gt;
                    &lt;/Style&gt;
                &lt;/GridView.ItemContainerStyle&gt;
                &lt;/GridView&gt;
            &lt;/JumpViewer.JumpView&gt;
</pre>
<p>Below is an illustration of the above Xaml and how the composite parts fit together.</p>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2011/09/JumpViewerJumpView.png" rel="shadowbox[sbpost-740];player=img;"><img class="alignleft size-full wp-image-744" title="JumpViewerJumpView" src="http://blogs.xamlninja.com/wp-content/uploads/2011/09/JumpViewerJumpView.png" alt="" width="487" height="457" /></a><br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
&nbsp;</p>
<p>What is very cool is the new Wrap Grid which provides the ability to change the layout of Jump View in the code above I do this.</p>
<pre class="brush: xml">
&lt;WrapGrid ItemWidth=&quot;114&quot;
    ItemHeight=&quot;114&quot;
    MaximumRowsOrColumns=&quot;6&quot;
    VerticalChildrenAlignment=&quot;Center&quot; /&gt;
</pre>
<p>In order to change the layout of the grid we can simply change the number of Maximum Rows or Columns, for example changing this property to 1 will change the layout to look more like the standard search control in Metro. Therefore, a quick tweak with how many rows or columns you want means that you can change the experience depending on the content being visualised. I will cover off the Wrap Grid in a future post.</p>
<p>Next we need to look at the content part of the Jump Viewer.</p>
<pre class="brush: xml">
&lt;!--
    The content view renders the detailed items
--&gt;
&lt;JumpViewer.ContentView&gt;
    &lt;GridView ItemsSource=&quot;{Binding Source={StaticResource cvs2}}&quot;
              IsCrossSlideEnabled=&quot;True&quot;&gt;
    &lt;!--
        Main content template
    --&gt;
    &lt;GridView.ItemTemplate&gt;
        &lt;--
           Data template used to display the data
        --&gt;
        &lt;DataTemplate&gt;
            &lt;StackPanel Orientation=&quot;Horizontal&quot;
                Margin=&quot;12,10,0,0&quot;
                HorizontalAlignment=&quot;Left&quot;&gt;
                &lt;Image Source=&quot;{Binding Image}&quot;
                       Height=&quot;60&quot;
                       Width=&quot;60&quot;
                       VerticalAlignment=&quot;Center&quot;
                       Margin=&quot;0,0,10,0&quot; /&gt;
                &lt;TextBlock TextWrapping=&quot;Wrap&quot;
                           Style=&quot;{StaticResource ItemTitleStyle}&quot;
                           Width=&quot;240&quot;
                           VerticalAlignment=&quot;Center&quot;
                           Text=&quot;{Binding Title}&quot;
                           HorizontalAlignment=&quot;Left&quot;
                           FontFamily=&quot;{StaticResource SemiLightContentFontFamily}&quot; /&gt;
             &lt;/StackPanel&gt;
        &lt;/DataTemplate&gt;
    &lt;/GridView.ItemTemplate&gt;
    &lt;!--Group Style this will allow for the grouping visual effects that we want--&gt;
    &lt;GridView.GroupStyle&gt;
        &lt;GroupStyle&gt;
        &lt;!--Group Style Header template defines what controls we use in the header--&gt;
        &lt;GroupStyle.HeaderTemplate&gt;
            &lt;DataTemplate&gt;
                &lt;TextBlock Text=&#039;{Binding Name}&#039;
                           Foreground=&quot;{StaticResource PageForegroundBrush}&quot;
                           Margin=&quot;0,0,36,0&quot;
                           FontSize=&quot;{StaticResource HeaderLargeFontSize}&quot;
                           FontFamily=&quot;{StaticResource SemiBoldContentFontFamily}&quot; /&gt;
            &lt;/DataTemplate&gt;
        &lt;/GroupStyle.HeaderTemplate&gt;
        &lt;!--Group Style Container Style --&gt;
        &lt;GroupStyle.ContainerStyle&gt;
            &lt;Style TargetType=&quot;GroupItem&quot;&gt;
            &lt;Setter Property=&quot;Template&quot;&gt;
                &lt;Setter.Value&gt;
                    &lt;ControlTemplate TargetType=&quot;GroupItem&quot;&gt;
                    &lt;!--Change the orientation of the panel to change where the Group Header is positioned --&gt;
                        &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;
                            &lt;ContentPresenter Content=&quot;{TemplateBinding Content}&quot; /&gt;
                            &lt;ItemsControl x:Name=&quot;ItemsControl&quot;
                                          ItemsSource=&quot;{Binding GroupItems}&quot; /&gt;
                        &lt;/StackPanel&gt;
                    &lt;/ControlTemplate&gt;
                &lt;/Setter.Value&gt;
            &lt;/Setter&gt;
        &lt;/Style&gt;
        &lt;/GroupStyle.ContainerStyle&gt;
        &lt;GroupStyle.Panel&gt;
            &lt;ItemsPanelTemplate&gt;
            &lt;!--
                Provides a grid-style layout panel where each tile/cell can be variable size based on content.
            --&gt;
            &lt;VariableSizedWrapGrid Orientation=&quot;Vertical&quot;
                                   MaximumRowsOrColumns=&quot;6&quot; /&gt;
            &lt;/ItemsPanelTemplate&gt;
        &lt;/GroupStyle.Panel&gt;
        &lt;/GroupStyle&gt;
    &lt;/GridView.GroupStyle&gt;
        &lt;GridView.ItemsPanel&gt;
            &lt;ItemsPanelTemplate&gt;
                &lt;!--VirtualizingStackPanel VirtualizationMode=&quot;Recycling&quot; --&gt;
                &lt;StackPanel Orientation=&quot;Horizontal&quot; /&gt;
                &lt;/ItemsPanelTemplate&gt;
            &lt;/GridView.ItemsPanel&gt;
                    &lt;Button Visibility=&quot;Collapsed&quot; /&gt;
        &lt;/GridView&gt;
    &lt;/JumpViewer.ContentView&gt;
&lt;/JumpViewer&gt;
</pre>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2011/09/JumpViewerContent.png" rel="shadowbox[sbpost-740];player=img;"><img src="http://blogs.xamlninja.com/wp-content/uploads/2011/09/JumpViewerContent-1024x575.png" alt="" title="JumpViewerContent" width="700" height="375" class="alignleft size-large wp-image-745" /></a></p>
<p>&nbsp;<br />
As you can see the Content section of the Jump Viewer comprises another control, in this case a Grid View, which provides the horizontal scrolling experience. A new feature for Metro is the ability to apply a Group Style on both the List and Grid View controls which provide the ability to group the data if your data model supports it. I will go into more detail about Group Styles in a future post. For now what we should understand is that when providing a Group Style we need to ensure that we provide a data template that will visualise the data in the header template and we can change the orientation of the layout by changing the Stack Panel in the Item Container Style from Vertical to Horizontal. </p>
<p>The Grid View also needs a data template for the items and there is also another new layout control called the Variable Sized Wrap Grid which is being used to layout the items in the Grid View. Once again I am loving this new layout and I will talk in more detail about the control in a future post. The most important thing for now is to understand that like the Wrap Grid, we can change the orientation and the Maximum Rows Or Columns properties which effect the layout of the items in the Grid. Sweet!</p>
<p>You may have also noticed that I have commented out the Virtualizing Stack Panel, I had problems when I used this, not sure why this is and when I find out more details I will update the post.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/xaml/metro-controls-jump-viewer/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>WP7 Contrib &#8211; Bing Service Wrapper Part I &#8211; Location</title>
		<link>http://blogs.xamlninja.com/xaml/wp7-contrib-bing-service-wrapper-part-i-location</link>
		<comments>http://blogs.xamlninja.com/xaml/wp7-contrib-bing-service-wrapper-part-i-location#comments</comments>
		<pubDate>Fri, 24 Jun 2011 14:31:13 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[Bing Services]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[WP7]]></category>
		<category><![CDATA[WP7Contrib]]></category>
		<category><![CDATA[Xaml]]></category>
		<category><![CDATA[WP7Dev]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/?p=499</guid>
		<description><![CDATA[This being the first post about the Wrappers I thought that we should break the ice with the most commonly used service. Location. Out of all of the services this is the simplest to call but also we would suspect the most widely used. When you combine this service with the device location based WP7C [...]]]></description>
			<content:encoded><![CDATA[<p>This being the first post about the Wrappers I thought that we should break the ice with the most commonly used service. Location. Out of all of the services this is the simplest to call but also we would suspect the most widely used. When you combine this service with the device location based WP7C bits then you can build your geo location aware app and have it plotting to a map and moving in real-time, or you could be helping your user to find the location of an address.</p>
<p>In the sample for using the location service we tackle both of these scenarios.</p>
<p>So, I am going to jump straight in here and assume that you have either looked at the sample in the Spikes folder of the <a href="http://wp7contrib.codeplex.com/" target="_blank">WP7 Contrib</a> (WP7C) or you have some experience of using the Rest API provided by the Bing Maps endpoint. If you have not done this then I would suggest opening up the sample and taking a quick look at the Location View Model, its pretty straight forwards so you should be back in 10.</p>
<p>First off if you have not already created a project then you need too. If you are using MVVM and some sort of DI library cool, if not no worries. There are two different options provided by the Location Service from the Bing REST API; you can either use the Geo Coordinate Location of the device and pass this to the service in order to give you back a current address; or you can enter a location to find out what Geo Coordinate Location is.</p>
<p>If you are not already using the WP7C components in you app (shame on you J) then you need to add a couple of references in order to get this up and running, these include:-</p>
<ul>
<li>WP7Contrib.Services
<ul>
<li>BingMaps</li>
<li>BingMaps.Model</li>
<li>Location</li>
</ul>
</li>
</ul>
<p>These are the basic bits that you need to get your geo location app up and running. Once we have included those assemblies then we need to define the interfaces we want to use and the data objects that correspond to the location service calls.</p>
<p>First up we need to declare the private fields so let’s go ahead and do that</p>
<pre class="brush: csharp">
private readonly IBingMapService bingMapService;
private readonly ILocationService locationService;
private LocationRect boundingRectangle;
private GeoCoordinate currentDeviceGeoCoordinate;
private IDisposable currentLocationObserver;
private RelayCommand selectFindMyCurrentLocationCommand;
private RelayCommand selectFindGeoLocationFromAddressCommand;
private Address address;
private LocationData locationDataByPoint;
</pre>
<p>&nbsp;</p>
<p>Next, we need to create a constructor for our VM. You will notice that not only am I using the ILocationService which is the WP7C’s Rx location component but we are also going to pass in a IBingMapService which is our wrapper that we will use to call the REST services. The other interfaces that I am using here are the navigation service and the logging component from WP7C.</p>
<pre class="brush: csharp">
public LocationViewModel(
INavigationService navigationService,
ILocationService locationService,
IBingMapService bingMapService,
ILog log)
: base(navigationService, log)
{
this.locationService = locationService;
this.bingMapService = bingMapService;
this.address = new Address {CountryRegion = &quot;UK&quot;, PostalCode = &quot;LE17 5ER&quot;};
}
</pre>
<p>&nbsp;</p>
<p>Currently, and this is consistent across all of our samples we are using Funq as our DI framework of choice, its light and simple which is why it’s great for WP7, we are not bound to Funq in anyway so if you want to use your Favourite DI then you can do so.</p>
<p>With our constructor defined we need to go ahead and do our register and resolve in the bootstrapper.</p>
<p>There is quite a bit of stuff happening in the bootstrapper, mainly because of the fact that we are taking advantage of the different components inside of the WP7C, now you don’t have to use these however if you need things like logging; want to store data; and if you have a design where you are not loading all the VM’s upfront take a look at the Last Message Replay. As this is the first in a series of posts we can deconstruct what is happening here in the future articles I will only reference this section.</p>
<p>The code below setups the Logging bits for us.</p>
<pre class="brush: csharp">
this.Container.Register&lt;ILogManager&gt;(c =&gt; new LoggingService(&quot;BingMaps&quot;));
this.Container.Register&lt;ILog&gt;(c =&gt; this.Container.Resolve&lt;ILogManager&gt;());
&lt;p&gt;var logManager = this.Container.Resolve&lt;ILogManager&gt;();
logManager.Enable();
</pre>
<p>&nbsp;</p>
<p>Here we setup the settings for the app and assign the key that we want to use for bing maps. The registered key in the code is registered to the WP7C so I would advise that you register, it does not take long and the key is generated instantly.</p>
<pre class="brush: csharp">
this.Container.Register&lt;IStoreSettings&gt;(c =&gt; new SettingsStore(this.Container.Resolve&lt;ILog&gt;()));
this.Container.Register&lt;ISettings&gt;(c =&gt; new Settings(&quot;Bing Key&quot;));
var serialisationAssemblies = new List&lt;Assembly&gt; { this.GetType().Assembly };
</pre>
<p>&nbsp;</p>
<p>Setup the cache provider and initialise it.</p>
<pre class="brush: csharp">
this.Container.Register&lt;ICacheProvider&gt;(c =&gt; new  IsolatedStorageCacheProvider(&quot;BingMaps&quot;, serialisationAssemblies,  c.Resolve&lt;ILog&gt;()));
var cache = this.Container.Resolve&lt;ICacheProvider&gt;();
System.Threading.ThreadPool.QueueUserWorkItem(state =&gt; cache.PreemptiveInitialise());
</pre>
<p>&nbsp;</p>
<p>Setup the last replay messenger.</p>
<pre class="brush: csharp">
this.Container.Register&lt;IMessenger&gt;(c =&gt; new LastMessageReplayMessenger());
</pre>
<p>&nbsp;</p>
<p>Setup the WP7C Navigation Service.</p>
<pre class="brush: csharp">
this.Container.Register&lt;INavigationService&gt;(

c =&gt; new ApplicationFrameNavigationService(((App)Application.Current).RootFrame));
</pre>
<p>&nbsp;</p>
<p>Setup the WP7C Network service</p>
<pre class="brush: csharp">
this.Container.Register&lt;INetworkService&gt;(c =&gt; new NetworkMonitor(5000));
</pre>
<p>&nbsp;</p>
<p>Setup the WP7C Storage service.</p>
<pre class="brush: csharp">
var assemblies = new List&lt;Assembly&gt; { this.GetType().Assembly, typeof(BaseModel).Assembly };
this.Container.Register&lt;IStorageService&gt;(c =&gt; new StorageService(assemblies, c.Resolve&lt;ILog&gt;()));
</pre>
<p>&nbsp;</p>
<p>As we are using the Resource Client from WP7C we also need to add this setup code into our bootstrapper.</p>
<pre class="brush: csharp">
this.Container.Register&lt;IEncodeProperties&gt;(c =&gt; new UrlEncoder());
this.Container.Register&lt;IHandleResourcesFactory&gt;(c =&gt; new ResourceClientFactory(c.Resolve&lt;ILog&gt;()));
</pre>
<p>&nbsp;</p>
<p>The final part is that we need to wire in the IBingMapService which needs to be resolved using some of the interfaces that we registered earlier.</p>
<pre class="brush: csharp">
this.Container.Register&lt;IBingMapService&gt;(c =&gt; new BingMapService(
c.Resolve&lt;IHandleResourcesFactory&gt;(),
c.Resolve&lt;IEncodeProperties&gt;(),
c.Resolve&lt;ICacheProvider&gt;(),
c.Resolve&lt;ISettings&gt;(),
c.Resolve&lt;ILog&gt;()));
</pre>
<p>&nbsp;</p>
<p>Ok, so we nearly have, all of the underlying plumbing done what we need to do next is to setup the VM locator. If you need more details on this please refer to the sample code. Once you have the VM locator updated we can go ahead and bind our Data Context up to the VM using the service locator pattern in Xaml.</p>
<p>As I mentioned at the start of this article, the UI’s are more about form and function, so our intentions are purely to visualise all the different types of data coming back from the service. So, for this we went with simple UI controls to make sure that the data being returned from our request is correct.</p>
<p>Now, that we have the plumbing in place, and some simple UI that displays the responses, our next step is to make our requests out to the Bing Services. This code is going to live in the VM.</p>
<p>The first thing on our list to implement is that we need to make our app location aware, everything you need to do this is already baked in the WP7C, it just requires a simple bit of Rx to get it wired in. In order to do this we need to leverage the ILocation Service that we injected into the VM as this will find out what our current location is.</p>
<pre class="brush: csharp">
private GeoCoordinate currentDeviceGeoCoordinate;
private IDisposable currentLocationObserver;
private void ExecuteSelectFindMyCurrentLocationCommand()
{
try
{
this.currentLocationObserver =
this.locationService.Location()
.ObserveOnDispatcher()
.Subscribe(geoCoordinate =&gt;
{
this.CurrentDeviceGeoCoordinate = geoCoordinate;
this.SearchForLocation(this.BuildLocationSearchForPoint());
});
}
catch (Exception exn)
{
MessageBox.Show(string.Format(&quot;Failed! Message - &#039;{0}&quot;, exn.Message), &quot;Location Search&quot;,                MessageBoxButton.OK);
}}
</pre>
<p>&nbsp;</p>
<p>Notice in the subscribe how we are assigning a value to the VM’s Current Device Geo Coordinate Property which is bound up in the view; also note that we are then doing a Search for a geo location and passing into this method the result from the Build Location Search For Point. We decided that in order for us to wrap up all the services and provide a common API from which users can use the services we would adopt a factory style pattern. So, what’s going on in the Build method? Well here we are calling out to the factory and asking it to create what we need in order to query the Bing services for dealing with the request.</p>
<pre class="brush: csharp">
private ILocationSearchPointCriterion BuildLocationSearchForPoint()
{
return CriterionFactory.CreateLocationSearchForPoint(this.CurrentDeviceGeoCoordinate);
}
</pre>
<p>&nbsp;</p>
<p>And that is all you need to add location awareness to your app, I hope that you agree with me that this is rather straight forwards. Next up we need to build out the search for location method, which is going to use the Bing wrapper service from the WP7C to search for a location. If you have looked over the code you will see that we have 2 overloaded methods, one which deals with Geo Location and the other which deals with addresses.</p>
<pre class="brush: csharp">
private void SearchForLocation(ILocationSearchPointCriterion criterion)
{
this.bingMapService.SearchForLocationUsingPoint(criterion)
.ObserveOnDispatcher()
.Subscribe(this.ProcessSearchLocationByPointResponse,
FailedSearch,
CompletedSearch);
}
</pre>
<p>&nbsp;</p>
<p>And for completeness I have included the code for the address mechanism below.</p>
<p>&nbsp;</p>
<pre class="brush: csharp">
private void SearchForLocation(ILocationSearchAddressCriterion criterion)
{
this.bingMapService.SearchForLocationUsingAddress(criterion)
.ObserveOnDispatcher()
.Subscribe(this.ProcessSearchLocationByAddressResponse,
FailedSearch,
CompletedSearch);
}
</pre>
<p>&nbsp;</p>
<p>Note that there are a couple of differences between the overloads; first the interface type that we are passing into our method for locations we always need to use the ILocationSearchPointCriterion and for addresses we need to use the ILocationSearchAddressCriterion; and the other difference is that we use a different method to deal with the response that we get sent from the Bing Services.</p>
<pre class="brush: csharp">
private void ProcessSearchLocationByPointResponse(LocationSearchResult result)
{
if (result == null)
{
return;
}
if (result.Locations.Count != 0)
this.LocationDataByPoint = result.Locations[0];
}
</pre>
<p>In order to successfully process the data and then work on this data the WP7C provides you with the data transformation classes that you need and does all the map and wrap code so that you don’t have to. In the code above this is illustrated by our use of the LocationDataByPoint property which uses the Location Data class from the WP7C, we are using databinding in the view and wiring up to this property from the VM .</p>
<p>So, just to recap what we have covered are a couple of things here; first we made our app Geo Location aware by using the WP7C Rx location service; which was then wired up to the Bing Services Wrapper and we used this to provide an address of the device&#8217;s current location; and for completeness we provide a way for the user to enter details of an address and the app responds with a Geo Location that corresponds to the address.</p>
<p>Admittedly we are doing some simple tasks here however its super important that we put in the ground work so that you can gain a deep understanding of how the wrappers work. We would really like to hear your feedback, if you have built an app using the Bing services we would also be interested in talking to you about your sceanrios.</p>
<p>In the next post I will dig into using the Route Service.</p>
<p><a href="http://awkwardcoder.blogspot.com/" target="_blank">Ollie</a> has some deep dive blog posts planned which are based around the patterns that he is using along with some gems of information around using Rx with these more traditional patterns so watch out for those.</p>
<p>Enjoy!</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/xaml/wp7-contrib-bing-service-wrapper-part-i-location/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WP7Contrib &#8211; Page Transitions and Navigation Service</title>
		<link>http://blogs.xamlninja.com/blend/wp7contrib-page-transitions-and-navigation-service</link>
		<comments>http://blogs.xamlninja.com/blend/wp7contrib-page-transitions-and-navigation-service#comments</comments>
		<pubDate>Mon, 21 Mar 2011 15:33:27 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[WP7]]></category>
		<category><![CDATA[WP7Contrib]]></category>
		<category><![CDATA[Xaml]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/?p=433</guid>
		<description><![CDATA[I finally got around to updating the page transistions in wp7 contrib last week, its something that has been on my list for awhile. For a complete sample project check out the sample in the spikes folder where you can also find lots of other samples illustrating other tennants of the contrib. The transitions used [...]]]></description>
			<content:encoded><![CDATA[<p>I finally got around to updating the page transistions in <a href="http://wp7contrib.codeplex.com/">wp7 contrib</a> last week, its something that has been on my list for awhile. For a complete sample project check out the sample in the spikes folder where you can also find lots of other samples illustrating other tennants of the contrib.</p>
<p>The transitions used in the <a href="http://wp7contrib.codeplex.com/">WP7C </a>are based around the great work of <a href="http://blogs.claritycon.com/kevinmarshall/author/kmarshall/">Kevin Marshall</a> who originally created the <a href="http://blogs.claritycon.com/blog/2010/10/13/wp7-page-transitions-sample/">transitions</a>, we like them becuase they are lighter on memory usage and slightly faster when compared to the page transitions found in the WP7 toolkit. Now that is not too say I dislike the transitions in the toolkit, I actually really like them mainly because we have the ability to define these transitions in Xaml and hopefully there will be some future design-time support in Blend where we could run these transitions. Xaml support for the transitions is definately on the vNext list for the WP7C as we believe its important for designers to able to change, apply and understand the different transitions that are available.</p>
<p>When comparing implementation details, the toolkit uses a custom Frame called a Transition Frame; and WP7C does this at a page level all the pages in your app have to sub class the Animated Base Page. Other differences include; the toolkit uses a Render Transform and WP7C uses Composite Transform; the WP7C uses the XamlReader.Load to setup the storyboards, however the toolkit has specific loose Xaml files that contain the storyboards.</p>
<p>So the new page transitions includes the different Rotate permutations for your page transitions, I also added in some new slide and fade transitions. You can play with these and all the other different transitions by downloading the sample app.</p>
<p>The other thing that I decided to add into the app was a very simple implementation of the WP7C navigation service. Page transitions and navigation are interconnected, when you navigate to a page you want to execute a transition between the current page and the new page, this is approapiate when going forwards or backwards. Normally we would wire up the WP7C Navigation Service in the bootstrapper of our app and use a DI framework to new this up. In order to keep everything super simple I am using the interface and manually newing up an instance, also note that I am not using a View Model this is simply to show the flexibility of the WP7C Navigation Service.</p>
<pre class="brush: csharp">
private WP7Contrib.Services.Navigation.INavigationService navigationService;

public MainPage()
{
        InitializeComponent();

       AnimationContext = LayoutRoot;
       this.navigationService = new WP7Contrib.Services.Navigation.ApplicationFrameNavigationService(
                                   ((App)Application.Current).RootFrame);
}
</pre>
<p>Notice how we grab the RootFrame and pass this in to the constructor of the WP7C Navigation Service the same code can be used in a bootstrapper. When using the WP7C transitions there is no requirement for us to change the base class of the frame in the App&#8217;s Initalize Phone App handler like we would do when using the toolkit.</p>
<pre class="brush: csharp">
private void InitializePhoneApplication()
{
    if (this.phoneApplicationInitialized)
    {
        return;
    }

    // Create the frame but don&#039;t set it as RootVisual yet; this allows the splash
    // screen to remain active until the application is ready to render.
    this.RootFrame = new TransitionFrame();
    this.RootFrame.Navigated += this.CompleteInitializePhoneApplication;

    // Handle navigation failures
    this.RootFrame.NavigationFailed += RootFrame_NavigationFailed;

    // Ensure we don&#039;t initialize again
    this.phoneApplicationInitialized = true;
}
</pre>
<p>Instead we need to hang all our pages from the Animated Base Page, pay close attention to; the constructor where we assign the Animated Context of our base page to the LayoutRoot of our page; and the overridden Get Animation where we are deciding which transitions to fire based on the Animation Type.</p>
<pre class="brush: csharp">
namespace PageTransition
{
    using System;

    using WP7Contrib.View.Transitions.Animation;

    public partial class Slide : AnimatedBasePage
    {
        public Slide()
        {
            InitializeComponent();

            AnimationContext = LayoutRoot;
        }

        protected override AnimatorHelperBase GetAnimation(AnimationType animationType, Uri toOrFrom)
        {
            if (animationType == AnimationType.NavigateForwardOut)
            {
                return new SlideLeftFadeOutAnimator { RootElement = LayoutRoot };
            }

            if (animationType == AnimationType.NavigateBackwardOut)
            {
                return new SlideRightFadeOutAnimator { RootElement = LayoutRoot };
            }

            if (animationType == AnimationType.NavigateForwardIn)
            {
                return new SlideLeftFadeInAnimator { RootElement = LayoutRoot };
            }

            return new SlideRightFadeInAnimator { RootElement = this.LayoutRoot };};
        }
    }
}
</pre>
<p>For completeness I have covered off the different permutations of Navigating forward or backward. The implemented page transitions have a corresponding Animator which makes it straightforward to implement the type of animation that you require. And that is everything you need in order to get page transitions working in your app. Once you have implemented the transitions you want then its a fairly simple task of using the WP7C Navigation Service to navigate to a page in your app.</p>
<pre class="brush: csharp">
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (AnimationList.SelectedIndex != -1)
    {
        switch (AnimationList.SelectedIndex)
        {
            case 0:
                this.navigationService.Navigate(new Uri(&quot;/View/Turnstile.xaml&quot;, UriKind.Relative));
                break;

            case 1:
                this.navigationService.Navigate(new Uri(&quot;/View/TurnstileFeather.xaml&quot;, UriKind.Relative));
                break;

            case 2:
                this.navigationService.Navigate(new Uri(&quot;/View/Continuum.xaml&quot;, UriKind.Relative));
                break;

            case 3:
                //slide right
                this.navigationService.Navigate(new Uri(&quot;/View/SlideRight.xaml&quot;, UriKind.Relative));
                break;

        }
    }
}
</pre>
<p>And we are done!</p>
<p>Couple of things to watch out for when implementing the page transitions</p>
<ol>
<li>Make sure that you have the correct base url in you WMAppManifest.xml.<br />
It should look something like this</p>
<pre class="brush: xml">
&lt;Tasks&gt;
      &lt;DefaultTask  Name =&quot;_default&quot; NavigationPage=&quot;View/MainPage.xaml&quot;/&gt;
    &lt;/Tasks&gt;
</pre>
<p>Even if you have a sub folder which contains your Views
</li>
<li>If you have already overriden the OnBackKeyPress handler remember to call the base implementation</li>
</ol>
<p>If you have created transitions and happy to share or have ideas for ones you would like to see then please contact me.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/blend/wp7contrib-page-transitions-and-navigation-service/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WP7 Contrib &#8211; the last messenger</title>
		<link>http://blogs.xamlninja.com/xaml/wp7-contrib-the-last-messenger</link>
		<comments>http://blogs.xamlninja.com/xaml/wp7-contrib-the-last-messenger#comments</comments>
		<pubDate>Thu, 27 Jan 2011 17:43:42 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[funq]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[WP7]]></category>
		<category><![CDATA[WP7Contrib]]></category>
		<category><![CDATA[Xaml]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/?p=309</guid>
		<description><![CDATA[As you may already be aware the WP7C uses MVVM Light as its preferred MVVM framework. Laurent has a great implementation of a Mediator style pattern that he has aptly name the Messenger. What I really like about this is the simplicity when it comes to implementing the baked in messages and how you can [...]]]></description>
			<content:encoded><![CDATA[<p>As you may already be aware the WP7C uses MVVM Light as its preferred MVVM framework. Laurent has a great implementation of a Mediator style pattern that he has aptly name the Messenger. What I really like about this is the simplicity when it comes to implementing the baked in messages and how you can extend the IMessenger interface that Laurent has included in MVVM Light. In general these generic messages cater for the majority of problems. However, there is a case that is not particularly well catered for. What follows is focused on WP7 however, this messenger component could be recompiled under your favourite SL build and used in your MVVM Light application today.</p>
<p>Before we start to roll you are going to make sure you have all the bits installed</p>
<p>WP7 Dev tools <a href="http://go.microsoft.com/fwlink/?LinkId=201927">ISO </a>download thanks <a href="http://blogs.msdn.com/b/jaimer/">JaimeR</a></p>
<p><a href="http://mvvmlight.codeplex.com/">MVVM Light Toolkit</a></p>
<p><a href="http://wp7contrib.codeplex.com">WP7 Contrib</a></p>
<p>Now if you are using some sort of DI component, at the moment my favourite is <a href="http://funq.codeplex.com/">funq </a>(<a href="http://ninject.org/">Ninject </a>will always have a place in my heart)  you may have found yourself in a situation where by you want to pass data from one VM to another, however the VM you want to pass the data to has not yet been created. There are various ways around this like not using DI and newing up all your VM during start-up so that this is no longer an issue. But, remember we are running under WP7 and performance is never going to be what it’s like in the browser.  We also want to take advantage of DI and all the goodness that it brings to the party.</p>
<p>Which came first, the chicken or the egg ??</p>
<p>An inherent problem with using Silverlight navigation and DI and having your VM’s lazily loaded. When you navigate to a page its not until this moment in time that your VM is constructed, therefore we hit this timing problem where the VM that is loaded up and trying to send a message to a VM which has yet to be loaded. What we first started out with was an implementation that was not so polished in that we would have a Register and Send Message being defined in the VM making the call; a Register Message defined in the receiving VM; and a callback Message in the receiving VM.</p>
<p>The way in which this works would be something like :-</p>
<ol>
<li>VM SearchPeople Registers for Message CurrentlySelectedPerson</li>
<li>In response to an interaction in the View (i.e. selecting an item in a list box). The associated VM SearchPeople Sends Message CurrentlySelectedPerson from within a INPC Property</li>
<li>In response to an interaction in the View (i.e. tapping an item in a list box). The associated VM SearchPeople ‘s  RelayCommand navigates to a new page Person Details</li>
<li>VM Person Details is constructed by our DI framework</li>
<li>VM Person Details constructor Registers for the Message CurrentlySelectedPerson</li>
<li>VM Person Details constructor fires a CallBack for the MessageCurrentlySelectedPerson</li>
<li>VM SearchPeople received the Message CurrentlySelectedPerson</li>
<li>VM SearchPeople Send the Message CurrentlySelectedPerson</li>
<li>VM PersonDetails received the Message CurrentlySelectedPerson</li>
</ol>
<p>This mechanism has to deal with the timing issue of the second VM not being loaded before the message is sent from the first, we end up in a situation where the first message never works and the subsequent messages always work. Therefore, by providing a callback in the second  and sending the message from here to the first VM we solve the problem, but its not as elegant as it could be.  The main issue here is that we are forced to send our messages twice due to the fact that our recipient VM has yet to be created and we need to give it a poke.</p>
<p>What becomes apparent is that the callback mechanism is not built for this type of work and we need a more structured and direct messaging mechanism. I had a chat with Ollie and he came up with a great messaging implementation. The rest of this post is concerned with how to use this Replay Messenger in your app,  <a href="http://awkwardcoder.blogspot.com/">Ollie </a>has a great post coming where he is going to go into more detailed post on the implementation details.</p>
<p>Laurent has provided an interface called IMessenger which provides developers with the ability to extend the and create our own Messages, nice&#8230;  Let’s make a start on building out a simple implementation. If you have <a href="http://blogs.xamlninja.com/wp-content/uploads/2011/01/WP7Contrib-Last-messenger.png" rel="shadowbox[sbpost-309];player=img;"><img class="alignright size-full wp-image-325" title="WP7Contrib Last messenger" src="http://blogs.xamlninja.com/wp-content/uploads/2011/01/WP7Contrib-Last-messenger.png" alt="" width="385" height="645" /></a>all the bits installed lets make a start. First off what is this app we are going to build, well is a simple app which has some sort of people list and we can select a person from the list and navigate to a more detailed page. Not the most exciting of apps but I want to keep the context fairly striaght forward so that we can concentrate on the problem and the solution rather than being distracted by other stuff. Saying that you are going too meet some other interface from WP7Contrib, ILogManager, ILog and INavigation Service. Over on the right you can see an screen shot showing the strcuture of the sample which can be found in the Spikes dir of the WP7Contrib.</p>
<p>My intentions below are not to walk you through every step we have some planned detailed posts and maybe even some screencasts to illustrate this points, therefore I am assumming that you know about the message classes availavble to you in MVVM Light Messaging and I am also assuming that you understand how to uses a DI framework.</p>
<p>Over on the right there is a screen grab of the solution if you want to fire this up then you can find it in the Spikes dir of the WP7Contrib. I have a model class called Person this is going to hold our data;2 pages main page and child page; 2 corresponding View Models main VM and child VM; in messages I have a base message and something called the Selected Person Message; a custom Base VM for WP7 which subclasses the MVVM Light VM Base; and finally I have a BootStrapper for my DI bits.</p>
<p>So first off what we need to do is take a look at the Selected Person Message as this is the message which is a wrapper for our data that we want to pass from the Main VM to the Child VM.</p>
<pre class="brush: csharp">
namespace ReplayLastMessageMessenger.ViewModel.Messages
{
    using System;

    using ReplayLastMessageMessenger.Model;

    /// &lt;summary&gt;
    /// The currently selected search result message.
    /// &lt;/summary&gt;
    public class SelectedPersonMessage : BaseMessage
    {
        #region Constants and Fields

        /// &lt;summary&gt;
        /// The person.
        /// &lt;/summary&gt;
        private readonly Person person;

        #endregion

        #region Constructors and Destructors

        /// &lt;summary&gt;
        /// Initializes a new instance of the &lt;see cref=&quot;SelectedPersonMessage&quot;/&gt; class.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;person&quot;&gt;
        /// The person.
        /// &lt;/param&gt;
        public SelectedPersonMessage(Person person)
        {
            this.person = person;
        }

        /// &lt;summary&gt;
        /// Initializes a new instance of the &lt;see cref=&quot;SelectedPersonMessage&quot;/&gt; class.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;exception&quot;&gt;
        /// The exception.
        /// &lt;/param&gt;
        public SelectedPersonMessage(Exception exception)
        {
            this.Exception = exception;
        }

        #endregion

        #region Properties

        /// &lt;summary&gt;
        /// Gets person.
        /// &lt;/summary&gt;
        public Person Person
        {
            get
            {
                return this.person;
            }
        }

        #endregion
    }
}
</pre>
<p>The code above is boiler plate making the implementation clean and repeatable, the code above is the message that we use for passing Property data between our VM&#8217;s. </p>
<p>That’s the message built. </p>
<p>Remember, what we have in our view is a list of items, and in our case a list of people and when you select an item from the list we navigate from this page to a details page, and we do this by sending a message that contains the data of the currently selected item from the list.</p>
<pre class="brush: csharp">
/// &lt;summary&gt;
/// Gets or sets CurrentlySelectedPerson.
/// &lt;/summary&gt;
public Person CurrentlySelectedPerson
{
    get
    {
        return this.currentlySelectedPerson;
    }

    set
    {
        this.SetPropertyAndNotify(ref this.currentlySelectedPerson, value, &quot;CurrentlySelectedPerson&quot;);
        this.NavigationService.Navigate(new Uri(&quot;/View/ChildPage.xaml&quot;, UriKind.Relative));
        this.MessengerInstance.Send(new SelectedPersonMessage(this.currentlySelectedPerson));
    }
}
</pre>
<p>Note, in the above code the Messenger is only responsible for sending message, its the Navigation Service that is responsible for the navigation from the list page to the details page and the details page displays the details of the data item selected from the list, therefore the Child VM will need to know the currently selected person. I will cover off the Navigation Service interface in a future post.</p>
<p>In order to do this we need to inject the IMessenger into each VM from our bootstrapper.  I am using funq for this so the code below is specific to funq however it’s the same drill register your wire ups with the container and then resolve them to an interface, This will provide a way of firing Registering and Sending those Currently Selected Person messages.</p>
<pre class="brush: csharp">
public class BootStrapper : IDisposable
{
    #region Constants and Fields

    /// &lt;summary&gt;
    /// The disposed.
    /// &lt;/summary&gt;
    private bool disposed;

    #endregion

    #region Constructors and Destructors

    /// &lt;summary&gt;
    /// Initializes a new instance of the &lt;see cref=&quot;BootStrapper&quot;/&gt; class.
    /// &lt;/summary&gt;
    public BootStrapper()
    {
        this.Container = new Container();

        this.ConfigureContainer();
    }

    #endregion

    #region Properties

    /// &lt;summary&gt;
    /// Gets Container.
    /// &lt;/summary&gt;
    public Container Container { get; private set; }

    #endregion

    #region Implemented Interfaces

    #region IDisposable

    /// &lt;summary&gt;
    /// The dispose.
    /// &lt;/summary&gt;
    public void Dispose()
    {
        if (this.Container != null)
        {
            this.Container.Dispose();
            this.Container = null;
        }
    }

    #endregion

    #endregion

    #region Methods

    /// &lt;summary&gt;
    /// The configure container.
    /// &lt;/summary&gt;
    private void ConfigureContainer()
    {
        this.Container.Register&lt;ILogManager&gt;(c =&gt; new LoggingService());

        this.Container.Register&lt;ILog&gt;(c =&gt; this.Container.Resolve&lt;ILogManager&gt;());

        this.Container.Register&lt;IMessenger&gt;(c =&gt; new LastMessageReplayMessenger());

        this.Container.Register&lt;INavigationService&gt;(
            c =&gt; new ApplicationFrameNavigationService(((App)Application.Current).RootFrame));

        this.Container.Register(
            c =&gt; new MainViewModel(c.Resolve&lt;INavigationService&gt;(), c.Resolve&lt;IMessenger&gt;(), c.Resolve&lt;ILog&gt;()));

        this.Container.Register(
            c =&gt; new ChildViewModel(c.Resolve&lt;INavigationService&gt;(), c.Resolve&lt;IMessenger&gt;(), c.Resolve&lt;ILog&gt;()));
    }

    #endregion
}
</pre>
<p>There are a couple of interfaces here that I am injecting into my VM&#8217;s these include the Navigation Service, the log manager and the log all of which we will talk about in future posts.</p>
<p>Again, Laurent has done a great job by providing a property in the View Model Base  called Messenger Instance which returns the instance of the messenger we injected in our bootstrapper, nice. There is a small nugget here as well to help with performance, as the registration of the message does not need to happen on the UI thread we can wrap this up like so.</p>
<p>The Main VM looks like this.</p>
<pre class="brush: csharp">
public MainViewModel(INavigationService navigationService, IMessenger messenger, ILog log)
    : base(navigationService, messenger, log)
{
    ThreadPool.QueueUserWorkItem(state =&gt;
    {
        // messaging
        this.MessengerInstance.Register&lt;NotificationMessageAction&lt;Person&gt;&gt;(
            this, message =&gt; message.Execute(this.CurrentlySelectedPerson));
    });
}
</pre>
<p>Now in the constructor of the Child VM its far sweeter code instead of the crufty callback and force a message in order to get the data we simply register for the replay message we are interested in, and provide a method to deal with the received message.</p>
<pre class="brush: csharp">
public ChildViewModel(INavigationService navigationService, IMessenger messenger, ILog log)
    : base(navigationService, messenger, log)
{
    ThreadPool.QueueUserWorkItem(state =&gt;
    {
        this.MessengerInstance.Register&lt;SelectedPersonMessage&gt;(this, this.OnReceiveMessage);
    });
}
</pre>
<p>The Xaml in the Main View looks like this.</p>
<pre class="brush: xml">
&lt;!--ContentPanel - place additional content here--&gt;
&lt;Grid x:Name=&quot;ContentPanel&quot;
        Grid.Row=&quot;1&quot;
        Margin=&quot;12,0,12,0&quot;&gt;
    &lt;ListBox ItemsSource=&quot;{Binding Path=Persons}&quot;
                SelectedItem=&quot;{Binding Path=CurrentlySelectedPerson, Mode=TwoWay}&quot;
                ItemTemplate=&quot;{StaticResource PersonsDataTemplate}&quot; /&gt;
&lt;/Grid&gt;
</pre>
<p>The Xaml in the Child View looks like this.</p>
<pre class="brush: xml">
&lt;!--ContentPanel - place additional content here--&gt;
&lt;Grid x:Name=&quot;ContentPanel&quot;
        Grid.Row=&quot;1&quot;
        Margin=&quot;12,0,12,0&quot;&gt;
    &lt;Grid.RowDefinitions&gt;
        &lt;RowDefinition Height=&quot;90&quot; /&gt;
        &lt;RowDefinition Height=&quot;513&quot; /&gt;
    &lt;/Grid.RowDefinitions&gt;
    &lt;StackPanel Orientation=&quot;Vertical&quot;&gt;
        &lt;TextBlock Text=&quot;{Binding CurrentlySelectedPerson.LastName}&quot;
                    FontFamily=&quot;{StaticResource PhoneFontFamilySemiLight}&quot;
                    FontSize=&quot;{StaticResource PhoneFontSizeMediumLarge}&quot; /&gt;
        &lt;TextBlock Text=&quot;{Binding CurrentlySelectedPerson.FirstName}&quot;
                    FontFamily=&quot;{StaticResource PhoneFontFamilySemiLight}&quot;
                    FontSize=&quot;{StaticResource PhoneFontSizeMedium}&quot; /&gt;
    &lt;/StackPanel&gt;
    &lt;Border Grid.Row=&quot;1&quot;
            BorderThickness=&quot;2&quot;&gt;
        &lt;Image Source=&quot;{Binding CurrentlySelectedPerson.ProfileImage}&quot; /&gt;
    &lt;/Border&gt;
&lt;/Grid&gt;
&lt;/Grid&gt;
</pre>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2011/01/ReplayLastMessagePeopleList.png" rel="shadowbox[sbpost-309];player=img;"><img src="http://blogs.xamlninja.com/wp-content/uploads/2011/01/ReplayLastMessagePeopleList.png" alt="" title="ReplayLastMessagePeopleList" style="border: 5px solid black; margin: 5px;" width="296" height="539" class="alignnone size-full wp-image-332" /></a><br />
<a href="http://blogs.xamlninja.com/wp-content/uploads/2011/01/ReplayLastMessagePersonDetails.png" rel="shadowbox[sbpost-309];player=img;"><img src="http://blogs.xamlninja.com/wp-content/uploads/2011/01/ReplayLastMessagePersonDetails.png" alt="" title="ReplayLastMessagePersonDetails" style="border: 5px solid black; margin: 5px;" width="296" height="539" class="alignnone size-full wp-image-333" /></a></p>
<p>Just to recap our steps were :-</p>
<ol>
<li>Define the Message which wraps up the data</li>
<li>Add the IMessenger interface as a parameter in the VM constructor</li>
<li>Register the IMessenger interface with the Last Message Replay Messenger</li>
<li>In the originator register the type of message data you’re interested in with the Notification Message Action</li>
<li>In the VM which is interested in the message register for the Message defined in step 1</li>
<li>Provide a method that deals with the received messages and setups up the data context of the View</li>
</ol>
<p>You can find out more information on the <a href="http://wp7contrib.codeplex.com">WP7Contrib</a> and find out what people are saying on twitter #WP7Contrib.</p>
<p>As i mentioned at the start if you are already using MVVM Light today then you can take advantage of the Last Replay Message. Ollie is going to follow up with a more detail post on the implementation details.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/xaml/wp7-contrib-the-last-messenger/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WP7 Contrib – Customising the DateTime Picker</title>
		<link>http://blogs.xamlninja.com/blend/wp7-contrib-customising-the-datetime-picker</link>
		<comments>http://blogs.xamlninja.com/blend/wp7-contrib-customising-the-datetime-picker#comments</comments>
		<pubDate>Sun, 23 Jan 2011 18:45:44 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[WP7]]></category>
		<category><![CDATA[WP7Contrib]]></category>
		<category><![CDATA[Xaml]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/?p=236</guid>
		<description><![CDATA[As you may already be aware there are two controls in the WP7 toolkit that provide the standard interactions and UI for selecting time and a date. Personally these are 2 of my favourite controls mainly due to the transitions and simple UI. However….. What happens when we are building an application that needs you [...]]]></description>
			<content:encoded><![CDATA[<p>As you may already be aware there are two controls in the WP7 toolkit that provide the standard interactions and UI for selecting time and a date. Personally these are 2 of my favourite controls mainly due to the transitions and simple UI. However….. What happens when we are building an application that needs you to enter credit card details ? Or you only want a subset of the provided controls i,e, a Month and a Year ? Unfortunately at the moment AFAIK  there is no way of doing this with the provided controls, its just not possible using Xaml either via the Style or the Template. We need to dig in a little deeper and find out what controls are actually powering these pickers. Well you don’t have to go too far before you find something called the Looping Selector control, the control provides an Item Template so that we can if we want add our own Data Template if so desired.</p>
<p>So why would you want to do this ? Well for us we need to provide an experience where the user of the app is prompted to enter in their credit card details. It seems only sensible to use the standard UI metaphor for picking a Date or a Time on WP7. As I found out this is just not possible and a level of customisation is required in order to achieve the interactions that we want along with the right experience.</p>
<p>This problem can be divided into two main pieces; data we will need to provided some subclassed data sources for day, month and year; UI we need to change the looping selectors visibility and do some work around hooking up the controls with data.</p>
<p>In the WP7 Contrib View project you can locate the DateTime Picker folder where the data sources are defined to support the picker. The main thing that we here is to reuse the same data source classes that are defined in the toolkit however we have changed the accessor to be public so that we can seem where we are using the control. The code below is here for completion and your viewing pleasure.</p>
<p>The Day DataSource</p>
<pre class="brush: csharp">
namespace WP7Contrib.View.Controls.DateTimePicker
{
    using System;

    public class DayDataSource : DataSource
    {
        // Methods
        /// &lt;summary&gt;
        /// Gets the relative to.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;relativeDate&quot;&gt;The relative date.&lt;/param&gt;
        /// &lt;param name=&quot;delta&quot;&gt;The delta.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        protected override DateTime? GetRelativeTo(DateTime relativeDate, int delta)
        {
            int num = DateTime.DaysInMonth(relativeDate.Year, relativeDate.Month);
            return new DateTime(relativeDate.Year, relativeDate.Month, ((((num + relativeDate.Day) - 1) + delta) % num) + 1);
        }
    }
}
</pre>
<p>The Month DataSource</p>
<pre class="brush: csharp">
namespace WP7Contrib.View.Controls.DateTimePicker
{
    using System;

    public class MonthDataSource : DataSource
    {
        // Methods
        /// &lt;summary&gt;
        /// Gets the relative to.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;relativeDate&quot;&gt;The relative date.&lt;/param&gt;
        /// &lt;param name=&quot;delta&quot;&gt;The delta.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        protected override DateTime? GetRelativeTo(DateTime relativeDate, int delta)
        {
            int num = 12;
            int month = ((((num + relativeDate.Month) - 1) + delta) % num) + 1;
            return new DateTime(relativeDate.Year, month, Math.Min(relativeDate.Day, DateTime.DaysInMonth(relativeDate.Year, month)));
        }
    }
}
</pre>
<p>The Year DataSource</p>
<pre class="brush: csharp">
namespace WP7Contrib.View.Controls.DateTimePicker
{
    using System;

    public class YearDataSource : DataSource
    {
        // Methods
        /// &lt;summary&gt;
        /// Gets the relative to.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;relativeDate&quot;&gt;The relative date.&lt;/param&gt;
        /// &lt;param name=&quot;delta&quot;&gt;The delta.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        protected override DateTime? GetRelativeTo(DateTime relativeDate, int delta)
        {
            if ((0x641 == relativeDate.Year) || (0xbb8 == relativeDate.Year))
            {
                return null;
            }
            int year = relativeDate.Year + delta;
            return new DateTime(year, relativeDate.Month, Math.Min(relativeDate.Day, DateTime.DaysInMonth(year, relativeDate.Month)));
        }
    }
}
</pre>
<p>Now that we have redefined these datasources we want to use in our customised implementation the next part is to take a look at the guts of the Xaml that is being used to compose the Picker as we mentioned earlier on there is the LoopingSelector that can be found in the Primitives namespace. This control is rather nice and does what it says on the tin, by providing a gambling machine style interaction. If you take a look at the Xaml defined in the DateTimePicker.xaml this is essentially what we need, so again this is pretty much a copy and paste job. I created a new user control called MonthYearPicker.xaml and stuffed the Xaml in here. The only changes that we need to make in the Xaml is to change the visibility of the looping selector that you don&#8217;t want to present to the user, in my case this was the day. Now we could do some more sophisticated stuff here, like provide an attached Dependency Property to control the visibility of the selector this is on the list so watch this space, but if you can think of any others shout.</p>
<pre class="brush: xml">
&lt;!-- LoopingSelectors --&gt;
        &lt;Grid
            Grid.Row=&quot;2&quot;
            HorizontalAlignment=&quot;Center&quot;&gt;
            &lt;Grid.ColumnDefinitions&gt;
                &lt;ColumnDefinition/&gt;
                &lt;ColumnDefinition/&gt;
                &lt;ColumnDefinition/&gt;
            &lt;/Grid.ColumnDefinitions&gt;
            &lt;Primitives:LoopingSelector
                x:Name=&quot;SecondarySelector&quot;
                Grid.Column=&quot;0&quot;
                Width=&quot;148&quot;
                ItemSize=&quot;148,148&quot;
                ItemMargin=&quot;6&quot;&gt;
                &lt;Primitives:LoopingSelector.ItemTemplate&gt;
                    &lt;DataTemplate&gt;
                        &lt;StackPanel
                            HorizontalAlignment=&quot;Left&quot;
                            VerticalAlignment=&quot;Bottom&quot;
                            Margin=&quot;6&quot;&gt;
                            &lt;TextBlock
                                Text=&quot;{Binding MonthNumber}&quot;
                                FontSize=&quot;54&quot;
                                FontFamily=&quot;{StaticResource PhoneFontFamilySemiBold}&quot;
                                Margin=&quot;0,-8&quot;/&gt;
                            &lt;TextBlock
                                Text=&quot;{Binding MonthName}&quot;
                                FontSize=&quot;20&quot;
                                FontFamily=&quot;{StaticResource PhoneFontFamilyNormal}&quot;
                                Foreground=&quot;{StaticResource PhoneSubtleBrush}&quot;
                                Margin=&quot;0,-2&quot;/&gt;
                        &lt;/StackPanel&gt;
                    &lt;/DataTemplate&gt;
                &lt;/Primitives:LoopingSelector.ItemTemplate&gt;
            &lt;/Primitives:LoopingSelector&gt;
            &lt;Primitives:LoopingSelector
                x:Name=&quot;TertiarySelector&quot;
                Grid.Column=&quot;1&quot;
                Width=&quot;0&quot;
                ItemSize=&quot;148,148&quot;
                ItemMargin=&quot;6&quot; Foreground=&quot;{x:Null}&quot; Visibility=&quot;Collapsed&quot;&gt;
                &lt;Primitives:LoopingSelector.ItemTemplate&gt;
                    &lt;DataTemplate&gt;
                        &lt;StackPanel
                            HorizontalAlignment=&quot;Left&quot;
                            VerticalAlignment=&quot;Bottom&quot;
                            Margin=&quot;6&quot;&gt;
                            &lt;TextBlock
                                Text=&quot;{Binding DayNumber}&quot;
                                FontSize=&quot;54&quot;
                                FontFamily=&quot;{StaticResource PhoneFontFamilySemiBold}&quot;
                                Margin=&quot;0,-8&quot;/&gt;
                            &lt;TextBlock
                                Text=&quot;{Binding DayName}&quot;
                                FontSize=&quot;20&quot;
                                FontFamily=&quot;{StaticResource PhoneFontFamilyNormal}&quot;
                                Foreground=&quot;{StaticResource PhoneSubtleBrush}&quot;
                                Margin=&quot;0,-2&quot;/&gt;
                        &lt;/StackPanel&gt;
                    &lt;/DataTemplate&gt;
                &lt;/Primitives:LoopingSelector.ItemTemplate&gt;
            &lt;/Primitives:LoopingSelector&gt;
            &lt;Primitives:LoopingSelector
                Grid.Column=&quot;2&quot;
                x:Name=&quot;PrimarySelector&quot;
                Width=&quot;148&quot;
                ItemSize=&quot;148,148&quot;
                ItemMargin=&quot;6&quot;&gt;
                &lt;Primitives:LoopingSelector.ItemTemplate&gt;
                    &lt;DataTemplate&gt;
                        &lt;StackPanel
                            HorizontalAlignment=&quot;Left&quot;
                            VerticalAlignment=&quot;Bottom&quot;
                            Margin=&quot;6&quot;&gt;
                            &lt;TextBlock
                                Text=&quot;{Binding YearNumber}&quot;
                                FontSize=&quot;54&quot;
                                FontFamily=&quot;{StaticResource PhoneFontFamilySemiBold}&quot;
                                Margin=&quot;0,-8&quot;/&gt;
                            &lt;TextBlock
                                Text=&quot; &quot;
                                FontSize=&quot;20&quot;
                                FontFamily=&quot;{StaticResource PhoneFontFamilyNormal}&quot;
                                Foreground=&quot;{StaticResource PhoneSubtleBrush}&quot;
                                Margin=&quot;0,-2&quot;/&gt;
                        &lt;/StackPanel&gt;
                    &lt;/DataTemplate&gt;
                &lt;/Primitives:LoopingSelector.ItemTemplate&gt;
            &lt;/Primitives:LoopingSelector&gt;
        &lt;/Grid&gt;
</pre>
<p>The final piece of the puzzle is the wire up, you maybe thinking why can&#8217;t you remove the looping selectors that you don&#8217;t want ? Well I thought that same thing, however its does not seem possible as the LoopingSelector wants 3 parts to be initialised; a Primary Part / Selector; a Secondary Part / Selector; and a Tertiary Part / Selector. Therefore we have to define all of the selectors in the Xaml. Now that we have that worked out we need to bring over some of the methods from the codebehind the picker from the toolkit.</p>
<p>Initialisation code</p>
<pre class="brush: csharp">
public MonthYearPicker()
        {
            this.InitializeComponent();
            this.PrimarySelector.DataSource = new YearDataSource();
            this.SecondarySelector.DataSource = new MonthDataSource();
            this.TertiarySelector.DataSource = new DayDataSource();

            ((DataSource)this.PrimarySelector.DataSource).AltSelectionChanged += this.HandleAltDataSourceSelectionChanged;
            ((DataSource)this.SecondarySelector.DataSource).AltSelectionChanged += this.HandleAltDataSourceSelectionChanged;
            ((DataSource)this.TertiarySelector.DataSource).AltSelectionChanged += this.HandleAltDataSourceSelectionChanged;

            this.InitializeDateTimePickerPage(this.PrimarySelector, this.SecondarySelector, this.TertiarySelector);
        }
</pre>
<p>Composition of the parts for the picker</p>
<pre class="brush: csharp">
        /// &lt;summary&gt;
        /// Gets a sequence of LoopingSelector parts ordered according to culture string for date/time formatting.
        /// &lt;/summary&gt;
        /// &lt;returns&gt;
        /// LoopingSelectors ordered by culture-specific priority.
        /// &lt;/returns&gt;
        protected override IEnumerable&lt;LoopingSelector&gt; GetSelectorsOrderedByCulturePattern()
        {
            return GetSelectorsOrderedByCulturePattern(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.ToUpperInvariant(), new char[] { &#039;Y&#039;, &#039;M&#039;, &#039;D&#039; }, new LoopingSelector[] { this.PrimarySelector, this.SecondarySelector, this.TertiarySelector });
        }
</pre>
<p>Handles the alt data source selection changed.</p>
<pre class="brush: csharp">
        /// &lt;summary&gt;
        /// Handles the alt data source selection changed.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;sender&quot;&gt;The sender.&lt;/param&gt;
        /// &lt;param name=&quot;e&quot;&gt;The &lt;see cref=&quot;System.Windows.Controls.SelectionChangedEventArgs&quot;/&gt; instance containing the event data.&lt;/param&gt;
        private void HandleAltDataSourceSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DataSource source = (DataSource)sender;
            if (source is YearDataSource)
            {
                // Set the year part of the value
                this.PrimarySelector.DataSource.SelectedItem = source.SelectedItem;
                if (source.SelectedItem != null &amp;&amp; this.Value.HasValue)
                {
                    this.Value = new DateTime(
                        ((DateTimeWrapper)source.SelectedItem).DateTime.Year, this.Value.Value.Month, 1);
                }
            }
            else if (source is MonthDataSource)
            {
                // Set the month part of the value
                this.SecondarySelector.DataSource.SelectedItem = source.SelectedItem;
                if (source.SelectedItem != null &amp;&amp; this.Value.HasValue)
                {
                    // Get the last day of the month
                    this.Value = new DateTime(
                        this.Value.Value.Year, ((DateTimeWrapper)source.SelectedItem).DateTime.Month, 1);
                }
            }
            else if (source is DayDataSource)
            {
                // We don&#039;t care about the day
                this.TertiarySelector.DataSource.SelectedItem = source.SelectedItem;
            }
        }
</pre>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2011/01/MonthYearPicker.png" rel="shadowbox[sbpost-236];player=img;"><img class="size-full wp-image-268 alignleft" style="border: 5px solid black; margin: 5px;" title="MonthYearPicker" src="http://blogs.xamlninja.com/wp-content/uploads/2011/01/MonthYearPicker.png" alt="" width="296" height="539" /></a><a href="http://blogs.xamlninja.com/wp-content/uploads/2011/01/MonthYearPicker1.png" rel="shadowbox[sbpost-236];player=img;"><img class="size-full wp-image-269 alignnone" style="border: 5px solid black; margin: 5px;" title="MonthYearPicker1" src="http://blogs.xamlninja.com/wp-content/uploads/2011/01/MonthYearPicker1.png" alt="" width="296" height="539" /></a></p>
<p>And there we have it DateTime Picker control which you can customised to show the selector that you want to show under different experiences. Our main job has been to refactored some of the code in the toolkit in order to access it from outside and also the changes to the xaml, nothing too taxing. I am pretty certain that this same approach could be used on the Time Picker, I have not tried this however there does not appear to be any particular reasons why this would not be possible.</p>
<p>As always interested in your thoughts and feedback&#8230;</p>
<p>What this space for more about the WP7Contrib soon to hit the shelves at a Codeplex near you&#8230;.</p>
<p>You can download the code from here on <a href="http://wp7contrib.codeplex.com/">Codeplex</a> and take a look at spikes where you can find this sample and others or you can get it from here</p>
<p><iframe title ="Preview" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="width:98px;height:115px;padding:0;background-color:#fcfcfc;" src="http://cid-118ee1873690fc1d.office.live.com/embedicon.aspx/WP7Contrib/MonthYearPickerApp.zip"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/blend/wp7-contrib-customising-the-datetime-picker/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The cleansing process</title>
		<link>http://blogs.xamlninja.com/uncategorized/the-cleansing-process</link>
		<comments>http://blogs.xamlninja.com/uncategorized/the-cleansing-process#comments</comments>
		<pubDate>Wed, 13 Oct 2010 11:32:04 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[WP7]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Xaml]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/uncategorized/the-cleansing-process</guid>
		<description><![CDATA[I spend a large proportion of my time collaborating with UI designers and UI interaction designers where we work closely together to produce interactive UI’s for customers. As someone who is a novice when it comes to Adobe Illustrator and Photoshop I am very reliant on the import functionality in Blend. In this post I [...]]]></description>
			<content:encoded><![CDATA[<p>I spend a large proportion of my time collaborating with UI designers and UI interaction designers where we work closely together to produce interactive UI’s for customers. As someone who is a novice when it comes to Adobe Illustrator and Photoshop I am very reliant on the import functionality in Blend. In this post I want to talk about a simple process that we have adopted to help with bringing those assets from AI and PS in our Xaml based projects.</p>
<p>Before the import features in Blend appeared we used the cool plug-in from Mike Swanson which would allow us to convert vector art work in Xaml. This was incredibility useful and mean that we reduce the time it took to convert these assets into Xaml and then modifying the Xaml in Kaxaml or in Blend. The process worked for us and we continued down this path until the import features in Blend improved and are now at a state where we can easily use the import functionality in Blend to convert these assets even easier.</p>
<p>But, that is not where the story ends, if you have tried out the import process on complex AI or PS visuals then you will have found that when Blend performs the import it positions each layer into a Canvas and will also import any images into the project as well. All in all this is cool however not so much when you have an existing project where you are happy with the code architecture and the folder structure of your application. And, this is what I want to dig into in this post is how to use the import functionality to your advantage.</p>
<p>Where do we start, ok so lets imagine that you have a project which you have setup or a developer on the team has created, its nicely structured and potentially uses MVVM or even a MVVM framework like MVVM Light. We also have a bunch of great looking designs that we need to convert into Xaml assets. We have a couple of options available at this point; we can import directly into the main solution or we can create a separate project a scratch project where we can import into. Admittedly at first I started out by importing directly into the main solution however this became a headache as the solution becomes polluted, by this I mean that when we do the import Blend will create a new folder in our project to hold the images that are referenced in the AI file however we are more than likely have an images folder in the project where all our images live. And for me this is where the management headache begins as we have to work out which images we want to keep and the ones we want to remove, and we also have to then move these images to the right folder and change the references to these images from the Xaml. All in all not too difficult when we break them down but on a large import this can become rather sticky very quickly.</p>
<p>Because of these issues what I have found is that importing into a scratch project is a smoother process for creating your Xaml assets and managing what images you want to keep. So the process goes something like this.</p>
<p>Create a scratch project and setup the folder structure for your Resource Dictionaries and images to mirror the same structure in the main project. Then import you AI or PS file into this project.</p>
<p>Next start to clean up your imported Xaml, the majority of the time you will want to ungroup the visual elements from their containing canvas as the visual elements will have been relatively positioned to mirror the layout defined in AI or PS. You will also find that the designer will have used a number of different layers to create the final appearance of an element. For example the designer may have used 4 different layers in order to create the colour of an element. In these cases my approach is to use the colour picker in Blend to find out what the colour is of the topmost layer, create this colour as a resource in your Resource Dictionary and then remove all the underlying layers until your left with the topmost then apply your newly created colour resource so that the visual element looks like the original. We could leave the visual elements as is however there are performance issues that we may encounter when doing this, in that if you have a list and you are planning on using this visual a number of times then those hidden layers are going to be present in the visual tree which means that the framework will render these and will have an impact on the performance of the application.</p>
<p>Other items to look out for are drop shadows on elements, when performing the import the drop shadows will be translated in a png images. In the majority of cases removing these images and replacing them with a drop shadow effect is the best mechanism, however there are some cases where the png works better. These situations are related to interaction design and occur when you are either; animating the visual elements on screen from one position to another; or you animating the drop shadow effect itself; in these circumstances then leaving the png is desirable and you may also consider using the EnableGPUAcceleration param at the plugin level along with setting the Bitmap Caching mode on your Xaml element.</p>
<p>By this stage you should now have cleansed your import and are ready to start styling and templating the imported visual elements into controls. There are two options available to you at this stage and they are related to your experience and confidence around the templating of the controls. </p>
<p>The first option is to group up the different visual layers that you want to make into the control, the majority of the time grouping them into a Grid or a&#160; Canvas will work for you. From here you can then right click on the layout panel that you created and select “Make into Control” option where you can select from the popup dialog the control that you want to create a style for. From here you can start to assign the visual elements to the parts associated with that template.</p>
<p>The second option is to drag onto the art board the control that you want to style and template and size the control to be the same as the visual elements. Right click on the control and select the “Create a Copy” sub menu option located under “Edit Template” option. This will then provide you with a default template which you can then start to modify so that it takes on the appearance of the visual.</p>
<p>The first option works well if you have intermit knowledge of the template you are creating, it can also work well when you know that you are creating styles and templates for controls which are of a fixed height and width. However, if this is not the case then the second option is a preferred route.</p>
<p>The styles, templates, colour and brush resources that you are using need to be added into the correct Resource Dictionaries. By following this approach you can then pick up the visual elements and merge them into your main solution along with the modifications to the Resource Dictionaries and moving any images that you are using into your images folder.</p>
<p>I hope this insight helps both designers who are creating assets using Adobe products to think about some best practices on how you construct your designs and for the Blend folks this should help with cleaning up the imported Xaml.</p>
<p>As always please let me know your thoughts and also what you have found works best for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/uncategorized/the-cleansing-process/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PathListBox Adventures &#8211; radial layout</title>
		<link>http://blogs.xamlninja.com/silverlight/pathlistbox-adventures-radial-layout</link>
		<comments>http://blogs.xamlninja.com/silverlight/pathlistbox-adventures-radial-layout#comments</comments>
		<pubDate>Mon, 29 Mar 2010 11:13:45 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[PathListBox]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Xaml]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/?p=224</guid>
		<description><![CDATA[The PathListBox ROCKS, if you have not heard of this control before then checkout Christians blog for more details and also his session at mix 10. The PathListBox solves some of the tricky issues related to creating custom panels for a ListBox or ItemsControl. Previously when we need custom layout of visual elements inside of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2010/03/RadialPanel.png" rel="shadowbox[sbpost-224];player=img;" target="_blank"><img style="margin: 5px auto; display: block; float: none; border-width: 0px;" title="RadialPanel" src="http://blogs.xamlninja.com/wp-content/uploads/2010/03/RadialPanel_thumb.png" border="0" alt="RadialPanel" width="632" height="484" /></a></p>
<p>The PathListBox ROCKS, if you have not heard of this control before then checkout <a href="http://electricbeach.org/" target="_blank">Christians</a> blog for more details and also his session at mix 10. The PathListBox solves some of the tricky issues related to creating custom panels for a ListBox or ItemsControl. Previously when we need custom layout of visual elements inside of these controls we would typically create a custom Panel and crank C# code and some positioning logic to layout the elements as we needed. However, with the introduction of the PathListBox we nolonger have to resort to building a panel and thus lowers the barrier to entry for designers who want to create custom layouts without having to be reliant on a developer to build the panel.</p>
<p>To get going with the PathListBox I wanted to create an simple Silverlight app which pulled back some results from digg, this is something which I have done in the past to illustrate the basics of MVVM in my session from PDC. While on the topic of MVVM its great to see that we now have an MVVM template inside of Blend that we can use. In this post I am not going to talk about the MVVM templates as I have only started out with them and so to give a comparison would not be justifiable at this stage, but I will posting an article when I have it straighten out in my head.</p>
<p>So for this first adventure I created a new MVVM Silverlight application and added a Model and a Service folder. As we already have the code for the digg service and the model created <em>I copied these classes and moved them into their respective folders in the project. Open up the VM that has been added into the project and we can see that it implements INPC. The other thing to notice is that the constructor in parameter less, which is unlike my VM’s where I would normally inject an interface. So for the purposes of this example i am going to new up the interface inside of the constructor.</em></p>
<p>Ok so there are 3 steps that we need to perform in order to recreate the radial panel visual layout that is illustrated above. First we need to create our path on the design surface and then add the PathListBox to the design surface and associate the path with the PathListBox. As with a regular ItemsControl or ListBox we need to bind it to a list of items which in this case is our collection of FeedItems. Blend 4 Beta does quite alot of work for free, you will notice it has created the DataTemplate, ItemContainerStyle and ItemPanelTemplate which is rather nice. So here we start our 3 Steps and each step is associated with the templates and style.</p>
<p>First select the DataTemplate of the PathListBox either from the crumb bar or from right clicking in the objects panel. What we need to do here is add a ChangePropertyAction which fires when we LeftMouseButtonDown on to the DataTemplate so that we can set a flag on the data bound object so that it gets removed from the current list and added to second list. Once we have added this we need to change the RotateTransform on the StackPanel to 90.</p>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxDatatemplateChangePropertyAction.png" rel="shadowbox[sbpost-224];player=img;"><img style="margin: 5px; display: inline; float: none; border-width: 0px;" title="PathListBoxDatatemplateChangePropertyAction" src="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxDatatemplateChangePropertyAction_thumb.png" border="0" alt="PathListBoxDatatemplateChangePropertyAction" width="644" height="476" /></a></p>
<p>Navigate back to the PathListBox and this time we want to edit the orientation on the items on the path so that they are OrientToPath and check the Wrap Items checkbox.</p>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxSettings.png" rel="shadowbox[sbpost-224];player=img;"><img style="display: inline; border-width: 0px;" title="PathListBoxSettings" src="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxSettings_thumb.png" border="0" alt="PathListBoxSettings" width="584" height="484" /></a></p>
<p>The second step is to move into our ItemContainerStyle for the PathListBox and change the VSM states so that we have a nice transition for the items when they are loaded and unloaded. With the release of Blend 4 Beta a new set of states have been added to the ListBoxItem. PathListBoxItem subclasses ListBoxItem and so we have the ability to modify the transitions for the BeforeLoaded and AfterLoaded states. For these I</p>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxStyleLayoutStates.png" rel="shadowbox[sbpost-224];player=img;"><img style="margin: 5px; display: inline; border-width: 0px;" title="PathListBoxStyleLayoutStates" src="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxStyleLayoutStates_thumb.png" border="0" alt="PathListBoxStyleLayoutStates" width="440" height="154" align="left" /></a></p>
<p>simply changed the Opacity on the root element so that we can have a simple fade in type transition. Next we need to change the length of the transition in this case to 0.3 seconds, and change the easing function to your desired choice. The other changes I made here was to enable the Fluid Layout and turned on the design time layout transitions so that you can see your transitions during design time. Navigate back to the PathListBox.</p>
<p>The final piece to the puzzle is to change the ItemPanelTemplate. Edit the template either via the assets panel or the crumb bar. Here we are looking to add  the FluidMoveBehavior on to our PathPanel which will be responsible for providing the animation effect for moving items between the two PathListBox’s.</p>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxItemsPanelTemplateFluidMoveBehavior.png" rel="shadowbox[sbpost-224];player=img;"><img style="margin: 5px auto; display: block; float: none; border-width: 0px;" title="PathListBoxItemsPanelTemplateFluidMoveBehavior" src="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxItemsPanelTemplateFluidMoveBehavior_thumb.png" border="0" alt="PathListBoxItemsPanelTemplateFluidMoveBehavior" width="644" height="446" /></a> The important things to note here include; we have selected the Children option from the AppliesTo dropdown as we want this particular FluidMoveBehavior to effect all the items in the ListBox; I changed the duration and also the easing functions that I wanted to use; I also selected the DataContext option from the Tag dropdown as I want to capture the data object associated with the item that is being animated. Navigate back to the PathListBox……</p>
<p>And we are done.</p>
<p>3 simple steps for you to add a radial panel layout into your project.</p>
<ol>
<li>Change the data template so that it can handle a user interaction</li>
<li>Change the ItemContainerStyle BeforeLoaded and AfterLoaded States</li>
<li>Change the ItemPanelTemplate by adding in the FluidMoveBehavior</li>
</ol>
<p>We also used ChangePropertyAction to manipulate the data in our collections exposed by the VM, and  we  used the FluidMoveBehavior to animate selected items from one PathListBox to another. The ability to do this without having to write any C# is a great step forwards, it does have some consequences but the advantages from my prospective outweigh the disadvantages.</p>
<p>The next thing that I want to do is animate each individual PathListBoxItem depending on where they are on the Path associated with the PathListBox.</p>
<p>All the code for this example you can find on my SkyDrive Folder.</p>
<p>&lt;iframe title =&#8221;Preview&#8221; scrolling=&#8221;no&#8221; marginheight=&#8221;0&#8243; marginwidth=&#8221;0&#8243; frameborder=&#8221;0&#8243; style=&#8221;width:98px;height:115px;padding:0;background-color:#fcfcfc;&#8221; src=&#8221;http://cid-118ee1873690fc1d.skydrive.live.com/embedicon.aspx/Silverlight4/MvvmApplication3.zip&#8221;&gt;&lt;/iframe&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/silverlight/pathlistbox-adventures-radial-layout/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Its a POC don&#8217;t worry about the data&#8230;</title>
		<link>http://blogs.xamlninja.com/blend/its-a-poc-dont-worry-about-the-data</link>
		<comments>http://blogs.xamlninja.com/blend/its-a-poc-dont-worry-about-the-data#comments</comments>
		<pubDate>Thu, 11 Mar 2010 13:37:43 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[Surface]]></category>
		<category><![CDATA[Xaml]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/blend/its-a-poc-dont-worry-about-the-data</guid>
		<description><![CDATA[In the last post my aim was to start a conversation around the advantages of building a visual data model. But this is a POC ? Why would you do this? Well its an interesting question and I am sure that there are folks out there who like to build prototypes and POC’s in this [...]]]></description>
			<content:encoded><![CDATA[<p>In the last post my aim was to start a conversation around the advantages of building a visual data model.</p>
<p>But this is a POC ? Why would you do this? </p>
<p>Well its an interesting question and I am sure that there are folks out there who like to build prototypes and POC’s in this way, but based on my experience this usually ends up taking longer as you find yourself adding a workaround to the existing workarounds resulting in friction between what you want to do and the limitations of the framework. So the approach that I prefer to use is to take some time out at the start of the process and deconstruct the visual designs and build out a data model to represent what information needs to be presented. We can then go off and create the simple factory classes to build these data structures and take full advantage of the features supported by the framework. In essence we are using the same techniques that we would use for a production quality application but slimming down a journey through the application using more appropriate patterns.</p>
<p>This simple process is not time consuming, helps clear up any potential misunderstanding of how the application will react based on certain interactions, and it means that when deconstructing the visual designs its easy to figure out what type of control you can use in order to build the visual and if the control you are thinking about using will support the interactions required. The additional bonus here is that if you want to go a step further then you easily wire in a simple MVVM pattern, again this is something that I do however its not an essential step.</p>
<p>What I also like about this approach is that POC’s are usually built in a short timeframe and are thus open to change on a regular basis and we need to have an approach which reduces churn. By having a good data model you can limit the pain when things change as you can easily change the data object to suit and then a simple change to the Xaml. The opposite of this can result in lots of conditional logic which becomes prone to bugs and also limiting the application to potentially just a clickable mockup.</p>
<p>The other benefit which results in this approach is the level of reusability that I can pull from the POC and move into the production application. By having taken the time to produce a data structure that is usable this means that I can potentially reuse all the existing data templates, data bindings, styles, templates and certain custom controls. Again from my experience this level of reusability is normally higher than when we push forwards with a more static and tightly coupled approach.</p>
<p>To put this into a better context, a number of Surface applications that I have been involved in recently have required a ScatterView with ScatterView Items as these control provide those all important gestures for NUI interactions out of the box. Cool, but we are faced with the options either; create a known number of items and potentially recreate the same style but with different hardwired data; or create a single data template and style and take advantage of the data bind features. This can easily be achieved by data binding to the DP’s provided by the ScatterView Item that controls its placement, its easy to maintain and manage when those known changes happen. It also provides us with the flexibility to extend certain aspects rapidly without getting freaked out by the amount of conditional logic being added to the app.</p>
<p>My approach here is a simple one, create a base class for all your data controlled visuals which allow you to provide point data information so that when the objects are created you can initialise them where they need to be placed on screen. You can also add into here some more properties such as Orientation and data bind your data object property to the Orientation DP. Properties such as CanScale etc I would manipulate in a Style for the ScatterView Item, however there is no reason why you could not add them into the base. My reasons for the using a Style is so that when I am working with the designer I can easily make changes to the Style when we are both using Blend, it also allows me to share the work with designers visually, this for me is essential, personally I am more of a visual guy I prefer to see something rather than read textual content a visual helps paint the picture in a more accurate way with less room for individual perceptions of a textual instruction or description.</p>
<p>This simple approach provides; the ability to place visual elements exactly where the designer wants them;animations can be built in order to animate these visual elements on and off screen, interrogating the strongly typed data types means that we can apply the required styles on demand; reduces the complexity of app by taking advantage of data binding.</p>
<p>Just to break this down a little further, with the Tag Heuer implementation, I created a bunch of data objects for the locations around the world, London, Los Angeles, Cape Town, Sydney etc; all of which subclass the same base called Location. Location, Travel and Watches, the three different states of the app all subclass a class providing the positioning logic which intern subclasses an abstract base implementing INPC. I then have a data templates for each of the locations that we need to visualise, London, Los Angeles, Cape Town, Sydney etc. The data templates deal nicely with presenting our data, however there is a problem with layout as some of the aforementioned locations need to be positioned from left to right and some need to be positioned from right to left. To achieve this visual effect I used a different style<br />
 one for left to right and a second for right to left and wired these into the data template. I could have written c# to flip the visual tree however in this instance it was more effective to rebuild the styles in Blend it also has the advantage that I can show the designer in Blend the visual created and make any additional tweaks required.</p>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2010/03/Illustrated_Travel.png" rel="shadowbox[sbpost-211];player=img;" target="_blank"><img style="border-bottom: 0px; border-left: 0px; margin: 5px; display: inline; float: none; border-top: 0px; border-right: 0px" title="Illustrated_Travel" border="0" alt="Illustrated_Travel" src="http://blogs.xamlninja.com/wp-content/uploads/2010/03/Illustrated_Travel_thumb.png" width="644" height="483" /></a> </p>
<p>I used the same technique for the F1 GP races and the watches area all of which have strongly typed data objects to encapsulate the visual information providing me with the advantages mentioned above to create and adapt quickly with the changes to the visual designs, it also allows me to take advantage of OO when it comes to adding additional properties to the base classes which will have a ripple effect down the object hierarchy.</p>
</p>
<p>In your next POC or prototype in WPF I hope that you will feel confident enough to try out this technique and reap the benefits that are at your disposal. Unfortunately the current version of Silverlight does not support implicit data templates, which in my humble opinion is a fundamental missing part of the Silverlight framework. Hopefully we will see this in a future release.</p>
<p> In the next post I am going to dig into how I built the watches section of the application and also dive into how interactions with the watch chrome and its content were created.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/blend/its-a-poc-dont-worry-about-the-data/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JC Decaux and Tag Heuer Surface Application deployed to Heathrow T5</title>
		<link>http://blogs.xamlninja.com/blend/jc-decaux-and-tag-heuer-surface-application-deployed-to-heathrow-t5</link>
		<comments>http://blogs.xamlninja.com/blend/jc-decaux-and-tag-heuer-surface-application-deployed-to-heathrow-t5#comments</comments>
		<pubDate>Thu, 25 Feb 2010 15:13:37 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[Surface]]></category>
		<category><![CDATA[Xaml]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/?p=172</guid>
		<description><![CDATA[This is really the start of a number of posts that I have been meaning to put together for a while now. These are centred around how to rapidly build prototypes. It’s a technique that I use on a regular basis both for WPF and for Silverlight. In order for me to get across how [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2010/02/T5_21.jpg" rel="shadowbox[sbpost-172];player=img;" target="_blank"><img style="display: inline; border: 0px;" title="T5_2" src="http://blogs.xamlninja.com/wp-content/uploads/2010/02/T5_2_thumb1.jpg" border="0" alt="T5_2" width="280" height="184" /></a> <a href="http://blogs.xamlninja.com/wp-content/uploads/2010/02/surface_unit_photos_manemailable1.jpg" rel="shadowbox[sbpost-172];player=img;" target="_blank"><img style="display: inline; border: 0px;" title="surface_unit_photos_manemailable" src="http://blogs.xamlninja.com/wp-content/uploads/2010/02/surface_unit_photos_manemailable_thumb1.jpg" border="0" alt="surface_unit_photos_manemailable" width="273" height="184" /></a></p>
<p>This is really the start of a number of posts that I have been meaning to put together for a while now. These are centred around how to rapidly build prototypes. It’s a technique that I use on a regular basis both for WPF and for Silverlight. In order for me to get across how effective this is it seems only right to provide context of how you can also take advantage of this technique.</p>
<p>More about that later, for this particular implementation I partnered with Splendid in order to produce an interactive experience for travellers at London Heathrow T5 lounges. The brief was to help raise brand awareness of the new Tag Heuer watches available and take advantage of the collaborate aspects provided by Surface.</p>
<p>The Tag Heuer Surface application has three main areas of functionality, all driven by the concept of time.<br />
<br/></p>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2010/02/04_travel_detail11.jpg" rel="shadowbox[sbpost-172];player=img;" target="_blank"><img style="margin-top: 5px; margin-right: 5px; margin-bottom: 5px; margin-left: 10px; display: inline; border: 0px initial initial;" src="http://blogs.xamlninja.com/wp-content/uploads/2010/02/04_travel_detail1_thumb1.jpg" border="0" alt="04_travel_detail1" width="244" height="184" align="right" /></a></p>
<p><strong>Travel Guide:</strong> The application displays the current time at your departure destination, displayed on a Tag Heuer watch display with moving hands. Using a stylized world map passengers can choose popular destinations and explore local time, travel duration and view local landmarks.</p>
<p><br/><br/><br/><br/><br/><br/><br />
<a href="http://blogs.xamlninja.com/wp-content/uploads/2010/02/06_sports_detail1.jpg" rel="shadowbox[sbpost-172];player=img;" target="_blank"><img style="margin-top: 5px; margin-right: 10px; margin-bottom: 5px; margin-left: 5px; display: inline; border: 0px initial initial;" src="http://blogs.xamlninja.com/wp-content/uploads/2010/02/06_sports_detail_thumb1.jpg" border="0" alt="06_sports_detail" width="244" height="184" align="left" /></a></p>
<p><strong><strong>Sports Finder:</strong></strong> Tag Heuer have a number of sports stars as ambassadors, we chose Lewis Hamilton as the trial location was the UK. Passengers can explore the world find the next Grand Prix including a  countdown and images of last years race.</p>
<p><br/><br/><br/><br/><br/><br/><br />
<a href="http://blogs.xamlninja.com/wp-content/uploads/2010/02/08_collection_detail1_zoom1.jpg" rel="shadowbox[sbpost-172];player=img;" target="_blank"><img style="margin-top: 5px; margin-right: 5px; margin-bottom: 5px; margin-left: 10px; display: inline; border: 0px initial initial;" src="http://blogs.xamlninja.com/wp-content/uploads/2010/02/08_collection_detail1_zoom_thumb1.jpg" border="0" alt="09_collection_detail1_resize" width="244" height="184" align="right" /></a><strong><strong>Watch Explorer: </strong></strong>A Tag Heuer Application wouldn’t be quite right without the ability to explore their classic  watch collection, passengers can use gesture to explore high-res images of the men’s and women’s collections with the ability to sign-up for an email on your favourite watch. The email contains details of the watch and your nearest location to purchase.<br />
<br/><br/><br/><br/><br/><br/><br />
For a UX developer there are some really rather cool interactions used in each of the areas. I am going to try and give a higher level overview of these areas  below and then jump into the detail in separate posts. The first of these are interactions present in each of the different functional pillars of the experience illustrated above and were designed so that visual elements could be placed into specific areas, animation of these items on and off screen and designed in such away that data bound objects provided the visual positioning information. The solution I used here was a combination of strongly typed data templates with model objects that contained the required coordinates of where to be positioned on screen and styles to create the required interactions.</p>
<p>When deconstructing the visual design I knew that the ScatterView Control would do the job nicely and having the coordinates in the model meant that we can take full advantage of data binding as each ScatterView Item has a centre and orientation DP which can be used to achieve this layout. Using a different ScatterViewItem Style provided the ability to choose different interactions and visuals based on which area of functionality is in use. Note there are 2 styles for the map points; a style for map points which are right aligned and a style for those which are left aligned. Using the strongly typed data templates and the use of data binding provides a clean and easy to achieve solution that provided the required interactions. The application was aware of its state and by changing the data based on state the usage of the strongly typed data templates come into their own as these state changes are triggered resulting in the new visuals to be displayed all done using data and data bindings in the Xaml.</p>
<p>For the travel section animated clocks were used and the TimeZoneInfo class provided the ability  to calculate the time in different time zones. Here I used a dispatch timer that was ticking away and then updating the value of the data object. Each of the different time zones were associated data objects of the current location using data binding and INPC meant that we can change the time in the data object and this will trigger the animations used to rotate the hands on the watch.</p>
<p>The watch section has cool interaction where there is a 2 level zoom mechanism, I broke this one down to<a href="http://blogs.xamlninja.com/wp-content/uploads/2010/02/09_collection_detail1_resize1.jpg" rel="shadowbox[sbpost-172];player=img;" target="_blank"><img style="margin-top: 5px; margin-right: 5px; margin-bottom: 5px; margin-left: 10px; display: inline; border: 0px initial initial;" src="http://blogs.xamlninja.com/wp-content/uploads/2010/02/09_collection_detail1_resize_thumb1.jpg" border="0" alt="09_collection_detail1_resize" width="244" height="184" align="right" /></a> be a ScatterViewItem which wraps a ScatterView. This allowed for an interaction which meant the user could  use a pinch gesture in increase the size of the outer ring and then a second pinch gesture can be used to manipulate the watch being displayed. What I like about this interaction design is that it allows the user to easy move and collaborate with other users interested in seeing the detailing of the watch. More importantly this also meant that I could take full advantage of data binding and strongly typed data templates.</p>
<p>As you may have noticed there is an underlying theme happening here, data and Xaml. For me WPF is really all about your data, get the data structure right that needs to be presented on screen and we can take full advantage of the framework and reduce the amount of C# code we write to a minimum.</p>
<p>links</p>
<p>The Moodie Report <a href="http://www.moodiereport.com/document.php?c_id=1113&amp;doc_id=23335">http://www.moodiereport.com/document.php?c_id=1113&amp;doc_id=23335</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/blend/jc-decaux-and-tag-heuer-surface-application-deployed-to-heathrow-t5/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Resource Dictionaries</title>
		<link>http://blogs.xamlninja.com/silverlight/resource-dictionaries</link>
		<comments>http://blogs.xamlninja.com/silverlight/resource-dictionaries#comments</comments>
		<pubDate>Tue, 23 Feb 2010 11:46:08 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Xaml]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/?p=156</guid>
		<description><![CDATA[In this post I thought that it would be interesting to share some of my thoughts that I have been having recently around Resource Dictionaries (RD) and how they are structured. It is very easy to just put everything into your generic.Xaml or even into your app.Xaml files and let the designer run away with [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I thought that it would be interesting to share some of my thoughts that I have been having recently around Resource Dictionaries (RD) and how they are structured. It is very easy to just put everything into your generic.Xaml or even into your app.Xaml files and let the designer run away with implementing their designs, but this is not too say that its the best way to roll.</p>
<p>From a developer prospective these files can become large very quickly and the result is a complete management headache when it comes to maintaining the styles, control and data templates. Its is also rather easy&#160; to allow this to happen as its in the Xaml and its what the designer produces, in effect its someone else&#8217;s responsibility. What is rather interesting and confusing at the same time is that Blend actually works very well when it comes to dealing with resources that are all in one file and it provides the designer with an easy way manage styles and templates. The other interesting thing about RD is that its actually at the heart of the Designer and Developer collaboration, its one of the areas where these two worlds collide. Therefore one of the ways in which we can help improve the workflow is to have a better understanding of RD and create some guidelines on how to best go about structuring them.</p>
<p>Unfortunately, even though RD are one of the core parts that make up the presentation layer there is very little information on best practices on how we should be doing this and why its important to get it right in order from which to have a good platform to move off from. Structuring RD in the wrong way can have rather serious performance problems.</p>
<p>There is a great article on the WPF Disciples pages providing very good advice on how to structure your RD and naming conventions, but I want to attempt to take it a little further. There are a number of different scenarios that I have come across and I am sure that there will be more along the way.&#160; These include; a POC application where this is built quickly and iteratively and requires a compelling UI but there is a high potential the application will not make it into production; themeable applications where a number of different themes can be applied to change the look and feel; and also applications that leverage 3rd party controls which have their own and sometimes rather interesting ways of how they are styled and templated. Each scenario is different but can be solved in the same way by using well structured RD to produce a clean, performant and easy to maintain application.</p>
<p>Ok, so how can we achieve a better structuring of the RD, help improve collaboration and provide a basic pattern and best practices in order to satisfy the different scenarios outlined above ?</p>
<p>Putting your RD in a separate project is the first thing to do, there are a number of advantages in doing this; but primarily this is about separation of concerns to help with workflow; and it helps to provide a blue print of a theme that can be reused over time. </p>
<p>In addition to the guidelines put forwards from the WPF list I am also going to add some more into the mix.</p>
<p>Suggested WPF Disciples Resources :-</p>
<p>BrushResources – solid brushes, linear gradient brushes and drawing brushes</p>
<p>ConverterResources &#8211; allows us to reference any of the converters by merging our resource dictionary with this file, rather than re-declaring our converters every time.</p>
<p>ImageResources &#8211; as above, allows us to declare an ImageSource once and reference it from anywhere.&#160; </p>
<p>TextResources -styles applied to textual elements (Hyperlinks, TextBlocks, etc.)</p>
<p>Additional Resources:-</p>
<p>Colours – for simple colours used as a swash for branding of clients colour palette.</p>
<p>DataTemplates – holds all the Data Templates used in the application.</p>
<p>Storyboards – holds all the Storyboard animations.</p>
<p>VectorGraphics – holds all the vectors graphics</p>
<p>CustomControls – holds styles and templates for those custom lookless controls</p>
<p>CommonControls- holds styles and templates for those common controls</p>
<p>Now the above list is not an exhaustive one and there is a high potential that this may change in the future but for now these provide a good platform from which to start. There are a number of ways in which you can slice and dice the RD used in your application some of which I will talk about shortly, but in general its best to think about the RD as a whole. The reason for this is that its best to see the Xaml assets as what constitutes your design and interaction of the UI that you are projecting onto the view for the user to experience. Therefore a change in the template or style means a&#160; complete new design. By thinking about them in a more holistic view as a the sum of all parts.</p>
<p>Therefore by splitting up the styles, templates etc into different high level RD categories provides the capabilities for the designers to work in an independent way and not have the constraints of working in the same project as the developers. The majority of times you will want to split out the RD into a separate project, and provide an area where they can create and design controls and elements. It also means that as they are working in a separate project they are completely separated from the developers but they are both working in the same solution.</p>
<p>What are those other views of RD that I mentioned earlier. Another potential way of looking at splitting up the RD is to break out the control templates and styles and place those into separate files. This will provide the ability to change the colours, font types etc and leave the control templates alone, which is great for those situations where you want to restyle the application and want to retain the layout of the controls. However, there are some problems with this approach; making significant changes to the style of controls will almost certainly mean that you will have to change the layout of the control, or building a custom control to handle the different styles; support in Blend for this type of structure is sub optimal in that it becomes more difficult to navigate and manage the styles and templates.</p>
<p>So why is it important to structure the RD in this way ? Why can they live all in the same Generic.Xaml file ? Is it the developer or the designer who owns the files ? How does this make my application more themeable ?</p>
<p>So those are a few of the questions which I have been asked about recently from both designers and developers, and they are all good questions and ones which i have also been thinking about hence my solution attempts to tackle these questions and provide a simpler implementation of how to use RD in your app.</p>
<p>One of the main problems with coming up with a good structure is the lack of guidance that is actually out there, plenty of high level information around some structure and naming conventions but no real information on the details. Rather frustratingly although we have gone head first into solving and building frameworks that address MVVM and come up with some notable solutions. It does feels like we have neglected an important area of the presentation layer.</p>
<p>What is rather interesting is how differently developers and designers perceive RD and this comes out in how they implement them in the app. </p>
<p>Developer : As a developer it is a natural and in the interest of best practices to split out each individual control so that each control is sat in its own RD. </p>
<p>Designer: As a designer its natural to think of all the controls at a higher level so that at set of individual controls contribute to the overall design of the app.</p>
<p>So as you can see neither side is right or wrong its their interpretation of RD which differs and this is natural as the different roles have different views and priorities on what is required to build the User Experience. What is interesting as well is that these opinions are skewed by the tools that they use and how they interpret and solve problems. The developer is very much focused on detail and implementation, mean while the designer is more interested in the higher level and the total experience of their design. </p>
<p>Therefore a combination of both these views seems to feel right where we split up the RD into a higher level categorisation with good naming conventions. This approach meets both parties needs and is Blendable allowing the designer to work in an environment which has a reduced reliance on the developer world and vice versa.</p>
<p>So I am hoping this that has made you think a little more about RD. In the next post I am going to talk more about how to implement the RD in your application and drill into the performance issues related to implementing RD and some sample code to help with guidance.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/silverlight/resource-dictionaries/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

