<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://mobileworld.appamundi.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Andy Wigley : Silverlight</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx</link><description>Tags: Silverlight</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 (Build: 30912.2823)</generator><item><title>What happens to network calls when your WP7 app goes dormant?</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2012/04/08/what-happens-to-network-calls-when-your-wp7-app-goes-dormant.aspx</link><pubDate>Sun, 08 Apr 2012 14:29:00 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:458</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;&lt;font size="2"&gt;Download&lt;/font&gt; &lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.00.04.58/NetworkingRecoveryOnReactivationSample.zip"&gt;sample code&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;In my Windows Phone training courses and workshops, I explain how the application lifecycle works, and how when your app loses focus – because the lock screen comes up, because your app is interrupted by an incoming phone call, because your code has called a launcher or a chooser, or because the user has pressed the start button to go and run something else – the OS takes a copy of the working memory of your app, suspends all threads and at this moment, your app has become &lt;strong&gt;&lt;em&gt;dormant&lt;/em&gt;&lt;/strong&gt;. Since the OS has simply stuck this memory snapshot into a cache, once the user has finished with the interruption and returns to your app, the memory snapshot is quickly reloaded and your app continues from where it left off, as if it has never been away. If however, your user runs *lots* of apps after your app is made dormant, then the OSs cache may become exhausted, so the memory snapshot for your app may be discarded and in this case, your app becomes tombstoned.&lt;/p&gt; &lt;p&gt;When your app reactivates, you can find out whether it has come back from dormant or from the ‘deader’ state of tombstoned, by looking at the &lt;font face="Consolas"&gt;IsApplicationinstancePreserved&lt;/font&gt; property of the &lt;font face="Consolas"&gt;ActivatedEventArgs&lt;/font&gt; object in the Application_Activated event handler:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:green;"&gt;// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
&lt;/span&gt;&lt;span style="color:blue;"&gt;private void &lt;/span&gt;Application_Activated(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;ActivatedEventArgs &lt;/span&gt;e)
{
    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(e.IsApplicationInstancePreserved)
    {
        &lt;span style="color:green;"&gt;// Back from dormant – generally not a lot you need to do
&lt;/span&gt;    }
    &lt;span style="color:blue;"&gt;else
    &lt;/span&gt;{
        &lt;span style="color:green;"&gt;// Back from Tombstoned – usually need to execute some logic to restore state
        &lt;font color="#000000"&gt;…&lt;/font&gt;&lt;/span&gt;
    }
}&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;So I have always taught that in general, you don’t really have to write any special code to handle the case where we are coming back from dormant.&lt;/p&gt;
&lt;p&gt;Except that is a bit of a simplification! It can &lt;u&gt;almost&lt;/u&gt; continue exactly from where it left off, but you still have to think about two specific scenarios where you might need to run some logic to get everything truly back to where you left off:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;- Time-dependent logic, where your app is waiting for something to happen on a specific timing, so you were using a timer object to trigger some action after some particular time interval. You will probably need to execute some logic on reactivation here to get everything straight. 
&lt;li&gt;- Networking calls. All networking calls are asynchronous, so what happens if your app becomes dormant when a networking request has been made, but the response hasn’t come back yet? &lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;Networking Calls and Dormant State&lt;/h2&gt;
&lt;p&gt;Well, what actually happens is that when your app is reactivated from a dormant state, any calls that were in progress will complete in error. The network call will complete by reporting a WebException with a Status of Request Cancelled. For example, if your are using the &lt;strong&gt;WebClient&lt;/strong&gt; API, the Request Cancelled status can be detected like this:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebDataService
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebClient &lt;/span&gt;webClient = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebClient&lt;/span&gt;();

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;WebDataService()
    {
        webClient.DownloadStringCompleted += &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DownloadStringCompletedEventHandler&lt;/span&gt;(webClient_DownloadStringCompleted);
    }

    &lt;span style="color:blue;"&gt;public void &lt;/span&gt;FetchUsingWebClient()
    {
         webClient.DownloadStringAsync(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Uri&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;http://localhost:8414/MyDataService.svc/DataObjects&amp;quot;&lt;/span&gt;, &lt;span style="color:#2b91af;"&gt;UriKind&lt;/span&gt;.Absolute));
    }

    &lt;span style="color:blue;"&gt;void &lt;/span&gt;webClient_DownloadStringCompleted(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;DownloadStringCompletedEventArgs &lt;/span&gt;e)
    {
        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(e.Error != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)
        {
            &lt;span style="color:blue;"&gt;if &lt;/span&gt;(e.Error &lt;span style="color:blue;"&gt;is &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebException&lt;/span&gt;)
            {
                &lt;span style="color:blue;"&gt;var &lt;/span&gt;wEx = e.Error &lt;span style="color:blue;"&gt;as &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebException&lt;/span&gt;;
                &lt;span style="color:blue;"&gt;if &lt;/span&gt;(wEx.Status == &lt;span style="color:#2b91af;"&gt;WebExceptionStatus&lt;/span&gt;.RequestCanceled)
                {
                    System.Diagnostics.&lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Request was cancelled&amp;quot;&lt;/span&gt;);
                }
                &lt;span style="color:blue;"&gt;else
                &lt;/span&gt;{
                    &lt;span style="color:green;"&gt;// Some other WebException. Do something…
&lt;/span&gt;                }
            }
            &lt;span style="color:blue;"&gt;else
            &lt;/span&gt;{
                System.Diagnostics.&lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;WebClient failed with &amp;quot; &lt;/span&gt;+ e.Error.Message);

                &lt;span style="color:green;"&gt;// Some other Exception. Do something…
&lt;/span&gt;            }
        }
        &lt;span style="color:blue;"&gt;else
        &lt;/span&gt;{
            System.Diagnostics.&lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Request completed successfully&amp;quot;&lt;/span&gt;);

            &lt;span style="color:green;"&gt;// Got response! Do something…
&lt;/span&gt;        }
    } 
} &lt;/pre&gt;&lt;pre class="code"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;h2&gt;Networking Calls and Tombstoned State&lt;/h2&gt;
&lt;p&gt;When your app is reactivated from a tombstoned state, any record or trace of networking calls that were in progress when the app was deactivated has disappeared. It is up to you to store some kind of state relating to any in progress networking calls – in persistent storage, or the Application or Page state dictionaries - when the app is deactivated. You can then retrieve that state data when the app reactivates from tombstoned and execute whatever logic you need to recover.&lt;/p&gt;
&lt;h1&gt;Creating a Networking Class that Recovers from Dormant and Tombstoned&lt;/h1&gt;
&lt;p&gt;Armed with the information above, we can now start thinking about how to create a class to use in our Windows Phone apps that can complete networking calls if the app is deactivated when a request has been made but the response has not come back yet. To do this, I developed a simple ODATA web service that returns a list of four dummy data objects. It’s included in the sample code for this post so I’m not going to waste time explaining how it works, but for those who are interested, I built it to serve some simple POCO objects (Plain Old CLR Objects) using excellent instructions I found in &lt;a href="http://lostintangent.com/post/3189655590/you-want-to-wrap-odata-around-what"&gt;this post&amp;nbsp; here&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;In a browser, the output from this service looks like this:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ODataService_5F00_55758CC8.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="ODataService" border="0" alt="ODataService" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ODataService_5F00_thumb_5F00_6B2F4F58.png" width="654" height="445" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;However, the key feature of this service is that I’ve programmed in an artificial 5 second delay on any response, so this gives us time to deactivate our app after the request has been made and before the service sends the response back, so we can test our networking class.&lt;/p&gt;
&lt;p&gt;It’s always a good idea to encapsulate related logic together into a single class, and in this case I have created a class called WebDataService which will contain the logic to make a request to the web service, return the results (or report an exception) to any clients of this class and it will – by the time we’ve finished – contain logic to recover from dormant or tombstoned state.&lt;/p&gt;
&lt;h2&gt;First Iteration – Basic Networking Class&lt;/h2&gt;
&lt;p&gt;My first iteration simply contains the logic to make the call, handle the response and return the received objects by firing a &lt;strong&gt;WebDataRequestCompleted&lt;/strong&gt; event, or if an error is encountered fire a &lt;strong&gt;WebDataRequestException&lt;/strong&gt; event. The client – which is MainForm in the sample app for this post – subscribes to these events so that it is notified when the request completes. &lt;/p&gt;
&lt;p&gt;It includes a few nice embellishments: for one thing, it uses a BackgroundWorker to make the request and handle the deserialization of the response on a worker thread so that we keep all that processing off the UI thread, and it contains a private bool property called &lt;strong&gt;isRequestActive&lt;/strong&gt; which is used to ensure this class can only handle one request at a time. It also uses &lt;a href="http://www.jeff.wilcox.name/2011/07/creating-a-global-progressindicator-experience-using-the-windows-phone-7-1-sdk-beta-2/"&gt;Jeff Wilcox’s Global Progress Indicator solution&lt;/a&gt; to show a progress bar while a request is in progress.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;FetchUsingWebClient&lt;/strong&gt; method sets the Accept header on the request to application/json to request the data from the ODATA service serialized as JSON, and in the &lt;strong&gt;webclient_DownloadStringCompleted&lt;/strong&gt; method, I use the LINQ to JSON capability of the JSON.NET library&amp;nbsp; (&lt;a title="http://json.codeplex.com/" href="http://json.codeplex.com/"&gt;http://json.codeplex.com/&lt;/a&gt;) to deserialize the JSON and to create the List of DataObject types that is the retrieved data.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;using &lt;/span&gt;System;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Collections.Generic;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.ComponentModel;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Linq;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Net;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;NetworkingRecoveryOnReactivationSample.Misc;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;NetworkingRecoveryOnReactivationSample.MyDataServiceReference;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Collections;

&lt;span style="color:blue;"&gt;namespace &lt;/span&gt;NetworkingRecoveryOnReactivationSample
{
    &lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebDataService
    &lt;/span&gt;{
        &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebClient &lt;/span&gt;webClient = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebClient&lt;/span&gt;();

        &lt;span style="color:blue;"&gt;public event &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;EventHandler&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;WebDataRequestCompletedEventArgs&lt;/span&gt;&amp;gt; WebDataRequestCompleted;
        &lt;span style="color:blue;"&gt;public event &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;EventHandler&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;WebDataRequestExceptionEventArgs&lt;/span&gt;&amp;gt; WebDataRequestException;

        &lt;span style="color:blue;"&gt;private bool &lt;/span&gt;isRequestActive { &lt;span style="color:blue;"&gt;set&lt;/span&gt;; &lt;span style="color:blue;"&gt;get&lt;/span&gt;; }

        &lt;span style="color:blue;"&gt;public &lt;/span&gt;WebDataService()
        {
            webClient.DownloadStringCompleted += &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DownloadStringCompletedEventHandler&lt;/span&gt;(webClient_DownloadStringCompleted);
        }

        &lt;span style="color:blue;"&gt;public void &lt;/span&gt;FetchUsingWebClient()
        {
            &lt;span style="color:green;"&gt;// WebClient instance only allows one request at a time
            &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;(!isRequestActive)
            {
                isRequestActive = &lt;span style="color:blue;"&gt;true&lt;/span&gt;;
                System.Diagnostics.&lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Starting new Request&amp;quot;&lt;/span&gt;);

                &lt;span style="color:green;"&gt;// Let&amp;#39;s do this properly and do our network calls and response processing on a worker thread
                &lt;/span&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;bgworker = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;BackgroundWorker&lt;/span&gt;();
                bgworker.DoWork += ((s, e) =&amp;gt;
                    {
                        webClient.Headers[&lt;span style="color:#a31515;"&gt;&amp;quot;Accept&amp;quot;&lt;/span&gt;] = &lt;span style="color:#a31515;"&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;;
                        webClient.DownloadStringAsync(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Uri&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;http://localhost:8414/MyDataService.svc/DataObjects&amp;quot;&lt;/span&gt;, &lt;span style="color:#2b91af;"&gt;UriKind&lt;/span&gt;.Absolute));
                    }
                );
                bgworker.RunWorkerAsync();

                ((&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;)&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;.Current).RootFrame.Dispatcher.BeginInvoke(() =&amp;gt;
                    &lt;span style="color:#2b91af;"&gt;GlobalLoading&lt;/span&gt;.Instance.IsLoading = &lt;span style="color:blue;"&gt;true&lt;/span&gt;);
            }
        }

        &lt;span style="color:blue;"&gt;void &lt;/span&gt;webClient_DownloadStringCompleted(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;DownloadStringCompletedEventArgs &lt;/span&gt;e)
        {
            isRequestActive = &lt;span style="color:blue;"&gt;false&lt;/span&gt;;

            ((&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;)&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;.Current).RootFrame.Dispatcher.BeginInvoke(()=&amp;gt;
                &lt;span style="color:#2b91af;"&gt;GlobalLoading&lt;/span&gt;.Instance.IsLoading = &lt;span style="color:blue;"&gt;false&lt;/span&gt;);

            &lt;span style="color:blue;"&gt;if &lt;/span&gt;(e.Error != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)
            {
                System.Diagnostics.&lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;WebClient failed with &amp;quot; &lt;/span&gt;+ e.Error.Message);

                &lt;span style="color:green;"&gt;// report exception to client
                &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;(WebDataRequestException != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)
                    WebDataRequestException(&lt;span style="color:blue;"&gt;this&lt;/span&gt;, &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebDataRequestExceptionEventArgs&lt;/span&gt;(e.Error));
            }
            &lt;span style="color:blue;"&gt;else
            &lt;/span&gt;{
                System.Diagnostics.&lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Request completed successfully&amp;quot;&lt;/span&gt;);

                &lt;span style="color:green;"&gt;// Deserialize using LINQ to JSON
                &lt;/span&gt;Newtonsoft.Json.Linq.&lt;span style="color:#2b91af;"&gt;JObject &lt;/span&gt;jObject = Newtonsoft.Json.Linq.&lt;span style="color:#2b91af;"&gt;JObject&lt;/span&gt;.Parse(e.Result);

                &lt;span style="color:blue;"&gt;var &lt;/span&gt;results = &lt;span style="color:blue;"&gt;from &lt;/span&gt;item &lt;span style="color:blue;"&gt;in &lt;/span&gt;jObject[&lt;span style="color:#a31515;"&gt;&amp;quot;d&amp;quot;&lt;/span&gt;]
                              &lt;span style="color:blue;"&gt;select &lt;/span&gt;(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DataObject
                                        &lt;/span&gt;{
                                            Id = (&lt;span style="color:blue;"&gt;int&lt;/span&gt;)item[&lt;span style="color:#a31515;"&gt;&amp;quot;Id&amp;quot;&lt;/span&gt;],
                                            Name = (&lt;span style="color:blue;"&gt;string&lt;/span&gt;)item[&lt;span style="color:#a31515;"&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;],
                                            Description = (&lt;span style="color:blue;"&gt;string&lt;/span&gt;)item[&lt;span style="color:#a31515;"&gt;&amp;quot;Description&amp;quot;&lt;/span&gt;],
                                            ANumber1 = (&lt;span style="color:blue;"&gt;int&lt;/span&gt;)item[&lt;span style="color:#a31515;"&gt;&amp;quot;ANumber1&amp;quot;&lt;/span&gt;],
                                            ANumber2 = (&lt;span style="color:blue;"&gt;int&lt;/span&gt;)item[&lt;span style="color:#a31515;"&gt;&amp;quot;ANumber2&amp;quot;&lt;/span&gt;]
                                        });

                &lt;span style="color:green;"&gt;// Fire event to inform observers that results are ready
                &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;(WebDataRequestCompleted != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)
                {
                    WebDataRequestCompleted(&lt;span style="color:blue;"&gt;this&lt;/span&gt;, &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebDataRequestCompletedEventArgs&lt;/span&gt;(results.ToList()));
                }
            }
        } 
    }

    &lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebDataRequestCompletedEventArgs &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;EventArgs
    &lt;/span&gt;{
        &lt;span style="color:blue;"&gt;public &lt;/span&gt;WebDataRequestCompletedEventArgs(&lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;DataObject&lt;/span&gt;&amp;gt; objects)
        {
            Data = objects;
        }
        &lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;DataObject&lt;/span&gt;&amp;gt; Data { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }
    }

    &lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebDataRequestExceptionEventArgs &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;EventArgs
    &lt;/span&gt;{
        &lt;span style="color:blue;"&gt;public &lt;/span&gt;WebDataRequestExceptionEventArgs(&lt;span style="color:#2b91af;"&gt;Exception &lt;/span&gt;exc)
        {
            Error = exc;
        }
        &lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Exception &lt;/span&gt;Error { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }
    }
}&lt;/pre&gt;&lt;pre class="code"&gt;
&lt;/pre&gt;
&lt;p&gt;To use this class, I create it and expose an instance of this class through a property in App.xaml.cs:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public partial class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;App &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;Application
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;private static &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebDataService &lt;/span&gt;webDataService;

    &lt;span style="color:blue;"&gt;public static &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebDataService &lt;/span&gt;WebDataService
    {
        &lt;span style="color:blue;"&gt;get
        &lt;/span&gt;{
            &lt;span style="color:blue;"&gt;if &lt;/span&gt;(webDataService == &lt;span style="color:blue;"&gt;null&lt;/span&gt;)
                webDataService = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebDataService&lt;/span&gt;();

            &lt;span style="color:blue;"&gt;return &lt;/span&gt;webDataService;
        }
    }&lt;/pre&gt;&lt;pre class="code"&gt;    …&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}
&lt;/pre&gt;
&lt;p&gt;and in my MainPage.xaml.cs, I hook and unhook the events and make the call to the &lt;strong&gt;FetchUsingWebClient&lt;/strong&gt; method to make the request. I’m not showing the XAML of the UI here, but if you download the sample, you’ll see that it has a button on it to make the request, and a ListBox to show the results:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public partial class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MainPage &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;PhoneApplicationPage
&lt;/span&gt;{
    &lt;span style="color:green;"&gt;// Constructor
    &lt;/span&gt;&lt;span style="color:blue;"&gt;public &lt;/span&gt;MainPage()
    {
        InitializeComponent();
    }

    &lt;span style="color:blue;"&gt;protected override void &lt;/span&gt;OnNavigatedTo(System.Windows.Navigation.&lt;span style="color:#2b91af;"&gt;NavigationEventArgs &lt;/span&gt;e)
    {
        &lt;span style="color:blue;"&gt;base&lt;/span&gt;.OnNavigatedTo(e);

        &lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;.WebDataService.WebDataRequestCompleted += &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;EventHandler&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;WebDataRequestCompletedEventArgs&lt;/span&gt;&amp;gt;(WebDataService_WebDataRequestCompleted);
    }

    &lt;span style="color:blue;"&gt;protected override void &lt;/span&gt;OnNavigatedFrom(System.Windows.Navigation.&lt;span style="color:#2b91af;"&gt;NavigationEventArgs &lt;/span&gt;e)
    {
        &lt;span style="color:blue;"&gt;base&lt;/span&gt;.OnNavigatedFrom(e);

        &lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;.WebDataService.WebDataRequestCompleted -= &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;EventHandler&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;WebDataRequestCompletedEventArgs&lt;/span&gt;&amp;gt;(WebDataService_WebDataRequestCompleted);
    }

    &lt;span style="color:blue;"&gt;void &lt;/span&gt;WebDataService_WebDataRequestCompleted(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;WebDataRequestCompletedEventArgs &lt;/span&gt;e)
    {
        Dispatcher.BeginInvoke(()=&amp;gt;
            &lt;span style="color:blue;"&gt;this&lt;/span&gt;.DataObjectsListBox.ItemsSource = e.Data
        );
    }

    &lt;span style="color:blue;"&gt;private void &lt;/span&gt;btnWebClient_Click(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;RoutedEventArgs &lt;/span&gt;e)
    {
        &lt;span style="color:green;"&gt;// Clear context first
        &lt;/span&gt;&lt;span style="color:blue;"&gt;this&lt;/span&gt;.DataObjectsListBox.ItemsSource = &lt;span style="color:blue;"&gt;null&lt;/span&gt;;

        &lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;.WebDataService.FetchUsingWebClient();
    }
}&lt;/pre&gt;&lt;pre class="code"&gt;
&lt;/pre&gt;
&lt;h2&gt;Implementing Automatic Recovery when Reactivating from Dormant&lt;/h2&gt;
&lt;p&gt;If you run the app using the code as shown above, and press the button on the main page, you’ll see the progress indicator at the top of the page and after about 5 seconds, the web service returns the data and it shows up in the ListBox. So far, so good!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/NetworkRecoverySample_5F00_1239E8CE.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="NetworkRecoverySample" border="0" alt="NetworkRecoverySample" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/NetworkRecoverySample_5F00_thumb_5F00_55C17423.png" width="267" height="491" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;However, if you press the Windows ‘Start’ button on the phone after pressing the WebClient button and before the response comes back, then the app is deactivated and is dormant. Press the Back button on the phone and your app is reactivated but the data does not appear. The data service class fires the &lt;strong&gt;WebDataRequestException&lt;/strong&gt; event to report that the request failed with a WebException.&lt;/p&gt;
&lt;p&gt;We can easily update the WebDataService class to allow it to retry the request in this situation. A simple solution would simply be to implement an automatic retry when the request fails with a Request Cancelled status, but I’ve implemented a slightly more refined solution. I’ve added a public &lt;strong&gt;bool&lt;/strong&gt; property called &lt;strong&gt;IsReactivatingFromDormant&lt;/strong&gt; which we can set from our Application_Activating event handler if we are reactivating from dormant and is just a flag that the logic in webClient_DownloadStringCompleted can query the very next time it processes a response. If the flag is set, and the request fails with a Request cancelled status, then we just make the request again. Changes are shown here in italics:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:gray;"&gt;&lt;strong&gt;&lt;em&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="color:green;"&gt;&lt;strong&gt;&lt;em&gt;Property that can be set from Application_Activating to allow retry of incomplete requests
&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:gray;"&gt;/// &amp;lt;/summary&amp;gt;
&lt;/span&gt;&lt;span style="color:blue;"&gt;public bool &lt;/span&gt;IsReactivatingFromDormant { &lt;span style="color:blue;"&gt;set&lt;/span&gt;; &lt;span style="color:blue;"&gt;private get&lt;/span&gt;;  }&lt;/em&gt;&lt;/strong&gt;

&lt;span style="color:blue;"&gt;&lt;/span&gt;&lt;font color="#0000ff"&gt;…&lt;/font&gt;&lt;/pre&gt;&lt;pre class="code"&gt;&lt;font color="#0000ff"&gt;&lt;/font&gt;
&lt;span style="color:blue;"&gt;void &lt;/span&gt;webClient_DownloadStringCompleted(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;DownloadStringCompletedEventArgs &lt;/span&gt;e)
{
    isRequestActive = &lt;span style="color:blue;"&gt;false&lt;/span&gt;;

    ((&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;)&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;.Current).RootFrame.Dispatcher.BeginInvoke(()=&amp;gt;
        &lt;span style="color:#2b91af;"&gt;GlobalLoading&lt;/span&gt;.Instance.IsLoading = &lt;span style="color:blue;"&gt;false&lt;/span&gt;);

    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(e.Error != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)
    {
&lt;strong&gt;&lt;em&gt;        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(e.Error &lt;span style="color:blue;"&gt;is &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebException&lt;/span&gt;)
        {
            &lt;span style="color:blue;"&gt;var &lt;/span&gt;wEx = e.Error &lt;span style="color:blue;"&gt;as &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebException&lt;/span&gt;;
            &lt;span style="color:blue;"&gt;if &lt;/span&gt;(wEx.Status == &lt;span style="color:#2b91af;"&gt;WebExceptionStatus&lt;/span&gt;.RequestCanceled)
            {
                System.Diagnostics.&lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Request was cancelled&amp;quot;&lt;/span&gt;);

                &lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:green;"&gt;// Are we just restarting from dormant?
                &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;(&lt;span style="color:blue;"&gt;this&lt;/span&gt;.IsReactivatingFromDormant)
                {
                    &lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:green;"&gt;// Request was probably cancelled due to the app going dormant
                    &lt;/span&gt;&lt;span style="color:blue;"&gt;this&lt;/span&gt;.IsReactivatingFromDormant = &lt;span style="color:blue;"&gt;false&lt;/span&gt;;
                    &lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:green;"&gt;// Retry
                    &lt;/span&gt;FetchUsingWebClient();
                }
            }
            &lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:blue;"&gt;else
            &lt;/span&gt;{
                System.Diagnostics.&lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Request failed with WebException: &amp;quot; &lt;/span&gt;+ wEx.Message);

                &lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;&lt;span style="color:green;"&gt;// report exception to client
                &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;(WebDataRequestException != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)
                    WebDataRequestException(&lt;span style="color:blue;"&gt;this&lt;/span&gt;, &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebDataRequestExceptionEventArgs&lt;/span&gt;(e.Error));
            }
        }
        &lt;/em&gt;&lt;/strong&gt;&lt;span style="color:blue;"&gt;&lt;strong&gt;&lt;em&gt;else&lt;/em&gt;&lt;/strong&gt;
        &lt;/span&gt;{
            System.Diagnostics.&lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;WebClient failed with &amp;quot; &lt;/span&gt;+ e.Error.Message);

            &lt;span style="color:green;"&gt;// report exception to client
            &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;(WebDataRequestException != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)
                WebDataRequestException(&lt;span style="color:blue;"&gt;this&lt;/span&gt;, &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;WebDataRequestExceptionEventArgs&lt;/span&gt;(e.Error));
        }
    }
    &lt;span style="color:blue;"&gt;else
    &lt;/span&gt;{
        System.Diagnostics.&lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Request completed successfully&amp;quot;&lt;/span&gt;);

        &lt;span style="color:green;"&gt;// Deserialize using LINQ to JSON
        &lt;font color="#000000"&gt;…&lt;/font&gt;&lt;/span&gt;
    }

&lt;strong&gt;&lt;em&gt;    &lt;span style="color:blue;"&gt;this&lt;/span&gt;.IsReactivatingFromDormant = &lt;span style="color:blue;"&gt;false&lt;/span&gt;;&lt;/em&gt;&lt;/strong&gt;
}&lt;/pre&gt;&lt;pre class="code"&gt; 
&lt;/pre&gt;
&lt;p&gt;You just set this flag from your Application_Activated event handler:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:green;"&gt;// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
&lt;/span&gt;&lt;span style="color:blue;"&gt;private void &lt;/span&gt;Application_Activated(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;ActivatedEventArgs &lt;/span&gt;e)
{
    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(e.IsApplicationInstancePreserved)
    {
        &lt;span style="color:green;"&gt;// Set flag on the data service to allow retry of requests that failed because we went dormant
        &lt;/span&gt;WebDataService.IsReactivatingFromDormant = &lt;span style="color:blue;"&gt;true&lt;/span&gt;;
    }
}
&lt;/pre&gt;
&lt;p&gt;With this enhancement, you can cause the app to be deactivated and then reactivated, and the request will be reissued without reporting an error.&lt;/p&gt;
&lt;h2&gt;Implementing Automatic Recovery when Reactivating from Tombstoned&lt;/h2&gt;
&lt;p&gt;If you now go into the Project Properties window and check the Tombstone upon Deactivation checkbox and repeat the exercise – deactivate and then reactivate – the app will be tombstoned instead of dormant when you deactivate it.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/TombstoneUponDeactivation_5F00_32B102B3.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="TombstoneUponDeactivation" border="0" alt="TombstoneUponDeactivation" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/TombstoneUponDeactivation_5F00_thumb_5F00_100CC438.png" width="724" height="476" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In this case no data is shown and no error is reported, because when the app is reactivated from a tombstoned state, a new instance of our WebDataService class is created and there is no record of the previous abandoned request. We must implement logic in our data service class to save its state on deactivation and record whether a request was in progress, and then to restore that state on reactivation and if that state tells us that a request *was* in progress, then reissue the request.&lt;/p&gt;
&lt;p&gt;This logic can be implemented by a pair of methods: &lt;strong&gt;SaveState&lt;/strong&gt; and &lt;strong&gt;RestoreState&lt;/strong&gt;:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;private const string &lt;/span&gt;WebDataServiceIsRequestActiveKey = &lt;span style="color:#a31515;"&gt;&amp;quot;WebDataServiceIsRequestActive&amp;quot;&lt;/span&gt;;

&lt;span style="color:gray;"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="color:green;"&gt;Method called from Application_Deactivating to save state
&lt;/span&gt;&lt;span style="color:gray;"&gt;/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;state&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color:green;"&gt;Application State Dictionary&lt;/span&gt;&lt;span style="color:gray;"&gt;&amp;lt;/param&amp;gt;
&lt;/span&gt;&lt;span style="color:blue;"&gt;public void &lt;/span&gt;SaveState(&lt;span style="color:#2b91af;"&gt;IDictionary&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;, &lt;span style="color:blue;"&gt;object&lt;/span&gt;&amp;gt; state)
{
    &lt;span style="color:green;"&gt;// save data on whether we have an active request in the state
    &lt;/span&gt;state[WebDataServiceIsRequestActiveKey] = isRequestActive;
}

&lt;span style="color:gray;"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="color:green;"&gt;Method called from Application_Activated if returning from Tombstoned
&lt;/span&gt;&lt;span style="color:gray;"&gt;/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;state&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color:green;"&gt;Application State Dictionary&lt;/span&gt;&lt;span style="color:gray;"&gt;&amp;lt;/param&amp;gt;
&lt;/span&gt;&lt;span style="color:blue;"&gt;public void &lt;/span&gt;RestoreState(&lt;span style="color:#2b91af;"&gt;IDictionary&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;, &lt;span style="color:blue;"&gt;object&lt;/span&gt;&amp;gt; state)
{
    &lt;span style="color:green;"&gt;// See if we have an incomplete request in the state
    &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;(state.ContainsKey(WebDataServiceIsRequestActiveKey))
    {
        &lt;span style="color:blue;"&gt;if &lt;/span&gt;((&lt;span style="color:blue;"&gt;bool&lt;/span&gt;)state[WebDataServiceIsRequestActiveKey])
        {
            &lt;span style="color:green;"&gt;// Restart the request
            &lt;/span&gt;FetchUsingWebClient();
        }
    }            
}&lt;/pre&gt;&lt;pre class="code"&gt;
&lt;/pre&gt;
&lt;p&gt;Simply call these methods from Application_Deactivating and Application_Reactivating to implement this new functionality:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:green;"&gt;// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
&lt;/span&gt;&lt;span style="color:blue;"&gt;private void &lt;/span&gt;Application_Activated(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;ActivatedEventArgs &lt;/span&gt;e)
{
    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(e.IsApplicationInstancePreserved)
    {
        &lt;span style="color:green;"&gt;// Set flag on the data service to allow retry of requests that failed because we went dormant
        &lt;/span&gt;WebDataService.IsReactivatingFromDormant = &lt;span style="color:blue;"&gt;true&lt;/span&gt;;
    }
    &lt;span style="color:blue;"&gt;else
    &lt;/span&gt;{
        &lt;span style="color:green;"&gt;// Restore state of the service
        &lt;/span&gt;WebDataService.RestoreState(&lt;span style="color:#2b91af;"&gt;PhoneApplicationService&lt;/span&gt;.Current.State);
    }
}

&lt;span style="color:green;"&gt;// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
&lt;/span&gt;&lt;span style="color:blue;"&gt;private void &lt;/span&gt;Application_Deactivated(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;DeactivatedEventArgs &lt;/span&gt;e)
{
    &lt;span style="color:green;"&gt;// Get the data service to save its state
    &lt;/span&gt;WebDataService.SaveState(&lt;span style="color:#2b91af;"&gt;PhoneApplicationService&lt;/span&gt;.Current.State);
}
&lt;/pre&gt;
&lt;h1&gt;Summary&lt;/h1&gt;
&lt;p&gt;This post has shown one technique for handling networking calls that can recover if the app is deactivated while a request is in progress. Every app has its own requirements, so this solution will not necessarily suit all situations. However, in many cases, the general approach shown here of placing your networking code into a dedicated class and implementing recovery logic will allow your apps to continue functioning correctly throughout the different stages of the application lifecycle.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=458" width="1" height="1"&gt;</description><enclosure url="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.00.04.58/NetworkingRecoveryOnReactivationSample.zip" length="3267891" type="application/x-zip-compressed" /><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Networking/default.aspx">Networking</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Windows+Phone+7/default.aspx">Windows Phone 7</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/wp7dev/default.aspx">wp7dev</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/_2300_wp7dev/default.aspx">#wp7dev</category></item><item><title>How to Databind SelectedItems of the ListPicker and RecurringDaysPicker</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2012/02/02/how-to-databind-selecteditems-of-the-listpicker-and-recurringdayspicker.aspx</link><pubDate>Thu, 02 Feb 2012 09:41:41 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:442</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>3</slash:comments><description>&lt;p&gt;The &lt;strong&gt;ListPicker&lt;/strong&gt; control from the Silverlight Toolkit is one of those Swiss Army Knife controls – very versatile and really useful. It wasn’t quite versatile enough for me though, as one thing it does *not* do is support &lt;em&gt;setting&lt;/em&gt; the &lt;strong&gt;SelectedItems&lt;/strong&gt; property when you have the control configured for multiple selections, which is something I wanted to do, and something you will certainly need to do if you ever want to pre-select some items from the list or you want to databind the SelectedItems property to a property in a data object. In this post, I will show you how to extend the ListPicker so that you can set the SelectedItems property. I will also show you how to do the same thing with the &lt;strong&gt;RecurringDaysPicker&lt;/strong&gt; control from the Silverlight Toolkit, which it turns out, is just a ListPicker configured to allow selection from the days of the week.&lt;/p&gt;  &lt;h2&gt;ListPicker in Single Selection Mode&lt;/h2&gt;  &lt;p&gt;The ListPicker is a bit like a ComboBox, and to use it you set its &lt;strong&gt;ItemsSource&lt;/strong&gt; property to say, a &lt;font face="Courier New"&gt;List&amp;lt;string&amp;gt;&lt;/font&gt; or a list of complex objects and if your list has five or fewer items, when the user taps on it, the list expands in-situ, (as shown with the &lt;strong&gt;background&lt;/strong&gt; selector in the following picture), and if your list has more than five items (as with the &lt;strong&gt;accent color&lt;/strong&gt; selector in the picture), then the control expands to what is called ‘Full Mode’, in other words it shows a new screen (right hand screenshot below) with all the items on it and the user can select from the list. And all that user experience is built into the control and comes for free!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ListPickerBasic_5F00_569D865B.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="ListPickerBasic" border="0" alt="ListPickerBasic" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ListPickerBasic_5F00_thumb_5F00_4CF51825.png" width="644" height="359" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In your code of course, you want to know which item the user selected, and the easy way to do this is to get the ListPicker’s &lt;strong&gt;SelectedItem&lt;/strong&gt; or &lt;strong&gt;SelectedIndex&lt;/strong&gt; property. More usually, you would use the SelectedIndex property particularly if you are using MVVM as it is easy to save the SelectedIndex when you serialize your viewmodel class and restore it when you deserialize the next time your user starts your app or the app returns from tombstoning. However, the SelectedIndex property is only useful when the ListPicker is in single selection mode, i.e. has its &lt;strong&gt;SelectionMode&lt;/strong&gt; property set to &lt;strong&gt;Single&lt;/strong&gt;, which is the default.&lt;/p&gt;  &lt;h2&gt;ListPicker in Multiple Selection Mode&lt;/h2&gt;  &lt;p&gt;The ListPicker also supports multiple selections from the user. To use it in this mode, you just set the &lt;strong&gt;SelectionMode&lt;/strong&gt; property to &lt;strong&gt;Multiple&lt;/strong&gt; and now when the user taps on the control, the full mode screen displays with checkboxes so the user can select more than one entry from the list. For example, the sample app for this post looks a bit like this, where the Football Teams control is a ListPicker in MultiSelect mode:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ListPickerMulti1_5F00_180812E8.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="ListPickerMulti1" border="0" alt="ListPickerMulti1" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ListPickerMulti1_5F00_thumb_5F00_59DED269.png" width="268" height="484" /&gt;&lt;/a&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ListPickerMulti2_5F00_483EC1D1.png"&gt;&lt;img style="background-image:none;border-right-width:0px;margin:0px 0px 0px 12px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="ListPickerMulti2" border="0" alt="ListPickerMulti2" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ListPickerMulti2_5F00_thumb_5F00_7838ED85.png" width="264" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;It’s quite simple to program the ListPicker for this kind of usage. First of all, you need to define the templates to use for the list displays, one to be used if the ListPicker items is less than or equal to 5, and one to be used for the full page display whn the number of items is more than that. I’ve defined them in the PhoneApplicationPage.Resources on MainPage.xaml:&lt;/p&gt;  &lt;pre class="code"&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;phone&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;PhoneApplicationPage.Resources&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DataTemplate &lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;PickerItemTemplate&amp;quot;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel &lt;/span&gt;&lt;span style="color:red;"&gt;Orientation&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Horizontal&amp;quot;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBlock &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Style&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:red;"&gt;PhoneTextNormalStyle&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot;/&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DataTemplate&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DataTemplate &lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;PickerFullModeItemTemplate&amp;quot;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel &lt;/span&gt;&lt;span style="color:red;"&gt;Orientation&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Horizontal&amp;quot;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBlock &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Style&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:red;"&gt;PhoneTextNormalStyle&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot;/&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBlock &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:red;"&gt;League&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;12 0 0 0&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Style&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:red;"&gt;PhoneTextSubtleStyle&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot;/&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DataTemplate&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;phone&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;PhoneApplicationPage.Resources&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And you then assign those templates where you declare the ListPicker control:&lt;/p&gt;

&lt;pre class="code"&gt;        &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid &lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;ContentPanel&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Grid.Row&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;12,0,12,0&amp;quot;&amp;gt;
&lt;span style="color:blue;"&gt;            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBlock &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;30&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Left&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;12,73,0,0&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;textBlock1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Multiselect ListPicker:&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Top&amp;quot; /&amp;gt; &lt;/span&gt;            &lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;toolkit&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListPicker &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;100&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Left&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;9,109,0,0&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;listPicker1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Top&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;441&amp;quot; 
                                &lt;/span&gt;&lt;span style="color:red;"&gt;SelectionMode&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Multiple&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;ItemsSource&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:red;"&gt;FootballTeams&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot;
 &lt;/span&gt;&lt;span style="color:blue;"&gt;                               &lt;/span&gt;&lt;span style="color:red;"&gt;Header&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Football Teams&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;FullModeHeader&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Football Teams&amp;quot; 
                                &lt;/span&gt;&lt;strong&gt;&lt;span style="color:red;"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:red;"&gt;PickerItemTemplate&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;FullModeItemTemplate&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:red;"&gt;PickerFullModeItemTemplate&lt;/span&gt;&lt;/strong&gt;&lt;span style="color:blue;"&gt;&lt;strong&gt;}&lt;/strong&gt;&amp;quot;/&amp;gt;
&lt;/span&gt;&lt;span style="color:blue;"&gt;            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;toolkit&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;RecurringDaysPicker &lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;recurringDaysPicker1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;198,259,0,0&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Left&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Top&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;212&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt;/&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBlock &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;41&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Left&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;12,275,0,0&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;textBlock2&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Recurring Days:&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Top&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;166&amp;quot; /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Button &lt;/span&gt;&lt;span style="color:red;"&gt;Content&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Set ViewModel Props&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;93&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Left&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;71,433,0,0&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;button1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Top&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;306&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Click&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;button1_Click&amp;quot; /&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You’ll notice that the templates contain &lt;strong&gt;TextBlock&lt;/strong&gt; controls that are databound to fields &lt;strong&gt;Name&lt;/strong&gt; and &lt;strong&gt;League&lt;/strong&gt;, and the &lt;strong&gt;ItemsSource&lt;/strong&gt; for the ListPicker is bound to something called &lt;strong&gt;FootballTeams&lt;/strong&gt;. FootballTeams is a property of type &lt;strong&gt;List&amp;lt;FootballTeam&amp;gt;&lt;/strong&gt; on my &lt;strong&gt;MainViewModel&lt;/strong&gt; class:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Collections.Generic;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.ComponentModel;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Collections.ObjectModel;

&lt;span style="color:blue;"&gt;namespace &lt;/span&gt;SelectedItemsDataBindSample
{
    &lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MainViewModel &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;INotifyPropertyChanged
    &lt;/span&gt;{
        &lt;span style="color:blue;"&gt;public const string &lt;/span&gt;FootballTeamsPropertyName = &lt;span style="color:#a31515;"&gt;&amp;quot;FootballTeams&amp;quot;&lt;/span&gt;;
        &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;FootballTeam&lt;/span&gt;&amp;gt; _footballTeams = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;FootballTeam&lt;/span&gt;&amp;gt;();

        &lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;FootballTeam&lt;/span&gt;&amp;gt; FootballTeams
        {
            &lt;span style="color:blue;"&gt;get
            &lt;/span&gt;{
                &lt;span style="color:blue;"&gt;return &lt;/span&gt;_footballTeams;
            }
            &lt;span style="color:blue;"&gt;set
            &lt;/span&gt;{
                &lt;span style="color:blue;"&gt;if &lt;/span&gt;(_footballTeams == &lt;span style="color:blue;"&gt;value&lt;/span&gt;)
                {
                    &lt;span style="color:blue;"&gt;return&lt;/span&gt;;
                }

                _footballTeams = &lt;span style="color:blue;"&gt;value&lt;/span&gt;;
                RaisePropertyChanged(SelectedTeamsPropertyName);
            }
        }

        &lt;span style="color:blue;"&gt;public &lt;/span&gt;MainViewModel()
        {
        }

        &lt;span style="color:blue;"&gt;public event &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;PropertyChangedEventHandler &lt;/span&gt;PropertyChanged;

        &lt;span style="color:blue;"&gt;private void &lt;/span&gt;RaisePropertyChanged(&lt;span style="color:blue;"&gt;string &lt;/span&gt;propertyName)
        {
            &lt;span style="color:blue;"&gt;if &lt;/span&gt;(PropertyChanged != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)
            {
                PropertyChanged(&lt;span style="color:blue;"&gt;this&lt;/span&gt;, &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;PropertyChangedEventArgs&lt;/span&gt;(propertyName));
            }
        }
    }
}&lt;/pre&gt;

&lt;p&gt;The &lt;strong&gt;FootballTeam&lt;/strong&gt; class looks like this:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;FootballTeam
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;public string &lt;/span&gt;Name { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color:blue;"&gt;public string &lt;/span&gt;League { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;FootballTeam()
    {  }

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;FootballTeam(&lt;span style="color:blue;"&gt;string &lt;/span&gt;name, &lt;span style="color:blue;"&gt;string &lt;/span&gt;league)
    {
        Name = name;
        League = league;
    }
}&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;The sample app creates an instance of &lt;strong&gt;MainViewModel&lt;/strong&gt; in my App.Xaml.cs, and exposes it via a property called ViewModel:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public partial class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;App &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;Application
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;private static &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MainViewModel &lt;/span&gt;viewModel = &lt;span style="color:blue;"&gt;null&lt;/span&gt;;

    &lt;span style="color:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="color:green;"&gt;A static ViewModel used by the views to bind against.
    &lt;/span&gt;&lt;span style="color:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color:green;"&gt;The MainViewModel object.&lt;/span&gt;&lt;span style="color:gray;"&gt;&amp;lt;/returns&amp;gt;
    &lt;/span&gt;&lt;span style="color:blue;"&gt;public static &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MainViewModel &lt;/span&gt;ViewModel
    {
        &lt;span style="color:blue;"&gt;get
        &lt;/span&gt;{
            &lt;span style="color:green;"&gt;// Delay creation of the view model until necessary
            &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;(viewModel == &lt;span style="color:blue;"&gt;null&lt;/span&gt;)
            {
                viewModel = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MainViewModel&lt;/span&gt;();
                viewModel.FootballTeams = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;FootballTeam&lt;/span&gt;&amp;gt;()
                                            {
                                                &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;FootballTeam&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;Leeds&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;&amp;quot;Championship&amp;quot;&lt;/span&gt;),
                                                &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;FootballTeam&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;Man U&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;&amp;quot;Premiership&amp;quot;&lt;/span&gt;),
                                                &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;FootballTeam&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;Man C&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;&amp;quot;Premiership&amp;quot;&lt;/span&gt;),
                                                &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;FootballTeam&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;Chelsea&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;&amp;quot;Premiership&amp;quot;&lt;/span&gt;),
                                                &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;FootballTeam&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;Liverpool&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;&amp;quot;Premiership&amp;quot;&lt;/span&gt;),
                                                &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;FootballTeam&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;Spurs&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;&amp;quot;Premiership&amp;quot;&lt;/span&gt;),
                                            };
            }

            &lt;span style="color:blue;"&gt;return &lt;/span&gt;viewModel;
        }
    }
}    &lt;/pre&gt;

&lt;p&gt;and the final piece of the jigsaw is to set this instance of &lt;strong&gt;MainViewModel&lt;/strong&gt; to be the &lt;strong&gt;DataContext&lt;/strong&gt; for MainPage.xaml. Notice also that I have set the &lt;strong&gt;SummaryForSelectedItemsDelegate&lt;/strong&gt; property to a method I have written called &lt;strong&gt;SummarizeTeams.&lt;/strong&gt; This is how you provide the ‘summary text’ representation of the users’ selections which is displayed on the MainPage, on the ‘normal’ rendering of the ListPicker before the user interacts with it, by providing a method like this that takes an &lt;strong&gt;IList&lt;/strong&gt; parameter and returns a string:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public partial class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MainPage &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;PhoneApplicationPage
&lt;/span&gt;{
    &lt;span style="color:green;"&gt;// Constructor
    &lt;/span&gt;&lt;span style="color:blue;"&gt;public &lt;/span&gt;MainPage()
    {
        InitializeComponent();
        &lt;span style="color:blue;"&gt;this&lt;/span&gt;.DataContext = &lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;.ViewModel;

        &lt;span style="color:blue;"&gt;this&lt;/span&gt;.listPicker1.SummaryForSelectedItemsDelegate = SummarizeTeams;
    }

    &lt;span style="color:blue;"&gt;protected string &lt;/span&gt;SummarizeTeams(&lt;span style="color:#2b91af;"&gt;IList &lt;/span&gt;selection)
    {
        &lt;span style="color:blue;"&gt;string &lt;/span&gt;str = &lt;span style="color:#a31515;"&gt;&amp;quot;*None Selected*&amp;quot;&lt;/span&gt;;

        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(&lt;span style="color:blue;"&gt;null &lt;/span&gt;!= selection &amp;amp;&amp;amp; selection.Count &amp;gt; 0)
        {
            &lt;span style="color:#2b91af;"&gt;StringBuilder &lt;/span&gt;contents = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;StringBuilder&lt;/span&gt;();
            &lt;span style="color:blue;"&gt;int &lt;/span&gt;idx = 0;
            &lt;span style="color:blue;"&gt;foreach &lt;/span&gt;(&lt;span style="color:blue;"&gt;object &lt;/span&gt;o &lt;span style="color:blue;"&gt;in &lt;/span&gt;selection)
            {
                &lt;span style="color:blue;"&gt;if &lt;/span&gt;(idx &amp;gt; 0) contents.Append(&lt;span style="color:#a31515;"&gt;&amp;quot;, &amp;quot;&lt;/span&gt;);
                contents.Append(((&lt;span style="color:#2b91af;"&gt;FootballTeam&lt;/span&gt;)o).Name);
                idx++;
            }
            str = contents.ToString();
        }

        &lt;span style="color:blue;"&gt;return &lt;/span&gt;str;
    }
}
 &lt;/pre&gt;

&lt;h2&gt;Getting – and Setting – the SelectedItems&lt;/h2&gt;

&lt;p&gt;After a user has selected items from the ListPicker, you can easily find out what the selected items are by hooking the SelectionChanged event and in the event handler, enumerate the SelectedItems collection. For example:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;private void &lt;/span&gt;listPicker1_SelectionChanged(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, System.Windows.Controls.&lt;span style="color:#2b91af;"&gt;SelectionChangedEventArgs &lt;/span&gt;e)
{
    &lt;span style="color:#2b91af;"&gt;StringBuilder &lt;/span&gt;msg = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;StringBuilder&lt;/span&gt;();
    msg.Append(&lt;span style="color:#a31515;"&gt;&amp;quot;Selected Teams:&amp;quot;&lt;/span&gt;);

    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(listPicker1.SelectedItems != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)
    {
        &lt;span style="color:blue;"&gt;foreach &lt;/span&gt;(&lt;span style="color:blue;"&gt;var &lt;/span&gt;item &lt;span style="color:blue;"&gt;in &lt;/span&gt;listPicker1.SelectedItems)
        {
            &lt;span style="color:blue;"&gt;var &lt;/span&gt;team = item &lt;span style="color:blue;"&gt;as &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;FootballTeam&lt;/span&gt;;
            msg.Append(&lt;span style="color:#a31515;"&gt;&amp;quot; &amp;quot; &lt;/span&gt;+ team.Name);
        }
    }

    System.Diagnostics.&lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(msg.ToString());
}&lt;br /&gt;&lt;/pre&gt;

&lt;h2&gt;Extending the ListPicker to Support Setting of SelectedItems&lt;/h2&gt;

&lt;p&gt;Using the standard control, there’s no way to programmatically set the SelectedItems, either by setting the SelectedItems property directly, or by exposing a collection of selected objects through a property of a ViewModel class and using databinding. This is because the SelectedItems property is a read-only property, as revealed if you browse the control class in the Object Browser:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ListPickerObjectBrowser_5F00_787570BA.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="ListPickerObjectBrowser" border="0" alt="ListPickerObjectBrowser" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ListPickerObjectBrowser_5F00_thumb_5F00_12D563D2.png" width="468" height="324" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So if you want to &lt;strong&gt;&lt;em&gt;set&lt;/em&gt;&lt;/strong&gt; the &lt;strong&gt;SelectedItems&lt;/strong&gt;, we must change the implementation of this property and add a setter to it as well.&lt;/p&gt;

&lt;p&gt;There are two ways to do this:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Download the source for the silverlight toolkit from &lt;a href="http://silverlight.codeplex.com"&gt;http://silverlight.codeplex.com&lt;/a&gt; and modify it yourself so you run with a customised version &lt;/li&gt;

  &lt;li&gt;Create your own custom control that inherits from ListPicker and implement the altered SelectedItems property in there. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I prefer option 2, as it turns out the code you need to write is pretty simple, and it’s a simpler solution – you can just add your reference to the Silverlight Toolkit assembly through NuGet or directly, and then inherit from the standard ListPicker in your custom control.&lt;/p&gt;

&lt;p&gt;The code you need to add a setter to the SelectedItems property looks like this:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;using &lt;/span&gt;Microsoft.Phone.Controls;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Collections;

&lt;span style="color:blue;"&gt;namespace &lt;/span&gt;SelectedItemsDataBindSample
{
    &lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ListPickerEx &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;ListPicker
    &lt;/span&gt;{
        &lt;span style="color:gray;"&gt;/// &amp;lt;summary&amp;gt;
        /// &lt;/span&gt;&lt;span style="color:green;"&gt;Gets or sets the selected items.
        &lt;/span&gt;&lt;span style="color:gray;"&gt;/// &amp;lt;/summary&amp;gt;
        &lt;/span&gt;&lt;span style="color:blue;"&gt;public new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IList &lt;/span&gt;SelectedItems
        {
            &lt;span style="color:blue;"&gt;get
            &lt;/span&gt;{
                &lt;span style="color:blue;"&gt;return &lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;IList&lt;/span&gt;)GetValue(SelectedItemsProperty);
            }
            &lt;span style="color:blue;"&gt;set
            &lt;/span&gt;{
                &lt;span style="color:blue;"&gt;base&lt;/span&gt;.SetValue(SelectedItemsProperty, &lt;span style="color:blue;"&gt;value&lt;/span&gt;);
            }
        }
    }
}&lt;/pre&gt;

&lt;p&gt;That’s it! You can do the same for the RecurringDaysPicker with identical code, and this is demonstrated as well in the sample code for this post.&lt;/p&gt;

&lt;p&gt;To use your custom control, first declare the namespace for your custom controls in the Xaml at the top of your page (in this example, these controls are just in the SelectedItemsDataBindSample namespace, in the project assembly):&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;phone&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;PhoneApplicationPage 
    &lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;SelectedItemsDataBindSample.MainPage&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;phone&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;shell&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;d&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;http://schemas.microsoft.com/expression/blend/2008&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;mc&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;http://schemas.openxmlformats.org/markup-compatibility/2006&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;toolkit&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit&amp;quot;
    &lt;/span&gt;&lt;strong&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;local&lt;/span&gt;&lt;/strong&gt;&lt;span style="color:blue;"&gt;&lt;strong&gt;=&amp;quot;clr-namespace:SelectedItemsDataBindSample&amp;quot;&lt;/strong&gt;
    &lt;/span&gt;&lt;span style="color:red;"&gt;mc&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Ignorable&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;d&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;d&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;DesignWidth&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;480&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;d&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;DesignHeight&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;768&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;FontFamily&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:red;"&gt;PhoneFontFamilyNormal&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;FontSize&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:red;"&gt;PhoneFontSizeNormal&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;Foreground&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:red;"&gt;PhoneForegroundBrush&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;SupportedOrientations&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Portrait&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Orientation&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Portrait&amp;quot;
    &lt;/span&gt;&lt;span style="color:red;"&gt;shell&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;SystemTray.IsVisible&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;True&amp;quot; 
    &amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;and where you declare the ListPicker, simply substitute local:ListPickerEx for toolkit:ListPicker:&lt;/p&gt;

&lt;pre class="code"&gt;        &lt;span style="color:green;"&gt;&amp;lt;!--ContentPanel - place additional content here--&amp;gt;
        &lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid &lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;ContentPanel&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Grid.Row&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;12,0,12,0&amp;quot;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;strong&gt;&lt;span style="color:#a31515;"&gt;local&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;/strong&gt;&lt;span style="color:#a31515;"&gt;&lt;strong&gt;ListPickerEx&lt;/strong&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;100&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Left&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;9,109,0,0&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;listPicker1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Top&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;441&amp;quot; 
                                &lt;/span&gt;&lt;span style="color:red;"&gt;SelectionMode&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Multiple&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;ItemsSource&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:red;"&gt;FootballTeams&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot;
                                &lt;/span&gt;&lt;span style="color:red;"&gt;SelectedItems&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:red;"&gt;SelectedTeams&lt;/span&gt;&lt;span style="color:blue;"&gt;, &lt;/span&gt;&lt;span style="color:red;"&gt;Mode&lt;/span&gt;&lt;span style="color:blue;"&gt;=TwoWay}&amp;quot;
                                &lt;/span&gt;&lt;span style="color:red;"&gt;SelectionChanged&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;listPicker1_SelectionChanged&amp;quot;
                                &lt;/span&gt;&lt;span style="color:red;"&gt;Header&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Football Teams&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;FullModeHeader&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Football Teams&amp;quot; 
                                &lt;/span&gt;&lt;span style="color:red;"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:red;"&gt;PickerItemTemplate&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;FullModeItemTemplate&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:red;"&gt;PickerFullModeItemTemplate&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot;/&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBlock &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;30&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Left&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;12,73,0,0&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;textBlock1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Multiselect ListPicker:&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Top&amp;quot; /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;strong&gt;&lt;span style="color:#a31515;"&gt;local&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;/strong&gt;&lt;span style="color:#a31515;"&gt;&lt;strong&gt;RecurringDaysPickerEx&lt;/strong&gt; &lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;recurringDaysPicker1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;198,259,0,0&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Left&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Top&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;212&amp;quot; 
                                         &lt;/span&gt;&lt;span style="color:red;"&gt;SelectedItems&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:red;"&gt;SelectedDays&lt;/span&gt;&lt;span style="color:blue;"&gt;, &lt;/span&gt;&lt;span style="color:red;"&gt;Mode&lt;/span&gt;&lt;span style="color:blue;"&gt;=TwoWay}&amp;quot; /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBlock &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;41&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Left&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;12,275,0,0&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;textBlock2&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Recurring Days:&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Top&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;166&amp;quot; /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Button &lt;/span&gt;&lt;span style="color:red;"&gt;Content&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Set ViewModel Props&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;93&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Left&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;71,433,0,0&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;button1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Top&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;306&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Click&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;button1_Click&amp;quot; /&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Button &lt;/span&gt;&lt;span style="color:red;"&gt;Content&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Set SelectedItems&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;93&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Left&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;71,514,0,0&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;button2&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Top&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;306&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Click&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;button2_Click&amp;quot; /&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Now you could have code similar to the following to programmatically set the SelectedItems:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:green;"&gt;// Get the full collection of items:
&lt;/span&gt;&lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;FootballTeam&lt;/span&gt;&amp;gt; allItems = listPicker1.ItemsSource &lt;span style="color:blue;"&gt;as &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;FootballTeam&lt;/span&gt;&amp;gt;;

&lt;span style="color:green;"&gt;// Set the SelectedItems to the 5th and 6th teams
&lt;/span&gt;listPicker1.SelectedItems = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ObservableCollection&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;object&lt;/span&gt;&amp;gt;() { allItems[4], allItems[5] };
 &lt;/pre&gt;

&lt;p&gt;The key thing to remember here is that the collection of items you set the SelectedItems property to must be a collection containing zero, 1 or more of the exact same objects that are in the main list of items that you supplied for the ItemsSource. The only qualification here is that if your data objects are just simple strings, as is the case with a RecurringDaysPicker for example, then you can just supply a collection of strings for SelectedItems as well – as long as the supplied strings exist in the ItemsSource as well of course.&lt;/p&gt;

&lt;h2&gt;Using Two-Way DataBinding with SelectedItems&lt;/h2&gt;

&lt;p&gt;You can also databind the SelectedItems property to a property in a View Model class. The trick here is to declare the property in your view model as type &lt;font size="2" face="Lucida Console"&gt;ObservableCollection&amp;lt;object&amp;gt;&lt;/font&gt;. In my&amp;#160; sample code for this post, I started out by doing the obvious thing of defining a property of type &lt;font size="2" face="Lucida Console"&gt;ObservableCollection&amp;lt;FootballTeam&amp;gt;&lt;/font&gt;, but it turns out that doesn’t work. Internally the control expresses its list of selected items as an &lt;font size="2" face="Lucida Console"&gt;ObservableCollection&amp;lt;object&amp;gt;&lt;/font&gt; so when you declare two-way data binding and the control tries to set the bound property in the View Model, it doesn’t know how to convert between an &lt;font size="2" face="Lucida Console"&gt;ObservableCollection&amp;lt;object&amp;gt;&lt;/font&gt; and an &lt;font size="2" face="Lucida Console"&gt;ObservableCollection&amp;lt;FootballTeam&amp;gt;&lt;/font&gt; – so just declare the bindable property in your ViewModel as &lt;font size="2" face="Lucida Console"&gt;ObservableCollection&amp;lt;object&amp;gt;&lt;/font&gt; and everything works fine.&lt;/p&gt;

&lt;p&gt;In the FootballTeam sample, the ViewModel class now has a new public property called &lt;strong&gt;SelectedTeams&lt;/strong&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MainViewModel &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;INotifyPropertyChanged
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;...&lt;/span&gt;&lt;/pre&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&lt;/span&gt;
    &lt;span style="color:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="color:green;"&gt;The &lt;/span&gt;&lt;span style="color:gray;"&gt;&amp;lt;see cref=&amp;quot;SelectedDays&amp;quot; /&amp;gt; &lt;/span&gt;&lt;span style="color:green;"&gt;property&amp;#39;s name.
    &lt;/span&gt;&lt;span style="color:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color:blue;"&gt;public const string &lt;/span&gt;SelectedTeamsPropertyName = &lt;span style="color:#a31515;"&gt;&amp;quot;SelectedTeams&amp;quot;&lt;/span&gt;;

    &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ObservableCollection&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;object&lt;/span&gt;&amp;gt; _mySelectedTeams = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ObservableCollection&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;object&lt;/span&gt;&amp;gt;();

    &lt;span style="color:gray;"&gt;/// &amp;lt;summary&amp;gt;
    /// &lt;/span&gt;&lt;span style="color:green;"&gt;Sets and gets the SelectedTeams property.
    &lt;/span&gt;&lt;span style="color:gray;"&gt;/// &lt;/span&gt;&lt;span style="color:green;"&gt;Changes to that property&amp;#39;s value raise the PropertyChanged event. 
    &lt;/span&gt;&lt;span style="color:gray;"&gt;/// &amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ObservableCollection&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;object&lt;/span&gt;&amp;gt; SelectedTeams
    {
        &lt;span style="color:blue;"&gt;get
        &lt;/span&gt;{
            &lt;span style="color:blue;"&gt;return &lt;/span&gt;_mySelectedTeams;
        }
        &lt;span style="color:blue;"&gt;set
        &lt;/span&gt;{
            &lt;span style="color:blue;"&gt;if &lt;/span&gt;(_mySelectedTeams == &lt;span style="color:blue;"&gt;value&lt;/span&gt;)
            {
                &lt;span style="color:blue;"&gt;return&lt;/span&gt;;
            }

            _mySelectedTeams = &lt;span style="color:blue;"&gt;value&lt;/span&gt;;
            RaisePropertyChanged(SelectedTeamsPropertyName);
        }
    }
    
    ...&lt;/pre&gt;

&lt;pre class="code"&gt;}&lt;/pre&gt;

&lt;p&gt;And in the MainPage.xaml, the &lt;strong&gt;SelectedItems&lt;/strong&gt; property is databound to the new property:&lt;/p&gt;

&lt;pre class="code"&gt;        &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid &lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;ContentPanel&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Grid.Row&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;12,0,12,0&amp;quot;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;local&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListPickerEx &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;100&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;HorizontalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Left&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;9,109,0,0&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;listPicker1&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;VerticalAlignment&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Top&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;441&amp;quot; 
                                &lt;/span&gt;&lt;span style="color:red;"&gt;SelectionMode&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Multiple&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;ItemsSource&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:red;"&gt;FootballTeams&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot;
                                &lt;/span&gt;&lt;strong&gt;&lt;span style="color:red;"&gt;SelectedItems&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:red;"&gt;SelectedTeams&lt;/span&gt;&lt;span style="color:blue;"&gt;, &lt;/span&gt;&lt;span style="color:red;"&gt;Mode&lt;/span&gt;&lt;/strong&gt;&lt;span style="color:blue;"&gt;&lt;strong&gt;=TwoWay}&amp;quot;&lt;/strong&gt;
                                &lt;/span&gt;&lt;span style="color:red;"&gt;SelectionChanged&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;listPicker1_SelectionChanged&amp;quot;
                                &lt;/span&gt;&lt;span style="color:red;"&gt;Header&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Football Teams&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;FullModeHeader&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Football Teams&amp;quot; 
                                &lt;/span&gt;&lt;span style="color:red;"&gt;ItemTemplate&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:red;"&gt;PickerItemTemplate&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;FullModeItemTemplate&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:red;"&gt;PickerFullModeItemTemplate&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot;/&amp;gt;
&lt;/span&gt;&lt;span style="color:blue;"&gt;           ...
        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Grid&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;If you run this sample and tap on the ListPickerEx on the screen and then select some teams, the control sets the SelectedTeams property of the underlying MainViewModel instance. If you tap on the &lt;strong&gt;Set ViewModel Props&lt;/strong&gt; button, the code behind directly sets the SelectedTeams property of the MainViewModel object, and through the magic of databinding, the UI updates. The sample also does the same thing for a &lt;strong&gt;RecurringDaysPicker&lt;/strong&gt; for which the solution is virtually identical.&lt;/p&gt;

&lt;p&gt;This sample also implements proper support for tombstoning and saving and restoring state when closed and later re-opened. To do this, it (de)serializes the MainViewModel object to and from isolated storage. This raises more interesting questions on how best to serialize an object that has a property (SelectedTeams) that exposes a list of object references rather than actual object instances. This is demonstrated in the sample code, but the explanation will be the subject for my next post…&lt;/p&gt;

&lt;p&gt;&lt;a href="https://skydrive.live.com/redir.aspx?cid=b36de4dd5a9179a1&amp;amp;resid=B36DE4DD5A9179A1!1335&amp;amp;parid=B36DE4DD5A9179A1!1333"&gt;Download the sample code&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=442" width="1" height="1"&gt;</description><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Windows+Phone+7/default.aspx">Windows Phone 7</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/wp7dev/default.aspx">wp7dev</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/_2300_wp7dev/default.aspx">#wp7dev</category></item><item><title>Silverlight Toolkit ToggleSwitch Databinding Bug</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2012/01/18/silverlight-toolkit-toggleswitch-databinding-bug.aspx</link><pubDate>Wed, 18 Jan 2012 15:23:00 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:430</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>3</slash:comments><description>&lt;p&gt;Are you using MVVM? Are you using the &lt;strong&gt;ToggleSwitch&lt;/strong&gt; from the Silverlight Toolkit? Have you got a weird bug where a ToggleSwitch that has its &lt;strong&gt;IsChecked&lt;/strong&gt; property databound to a &lt;strong&gt;bool&lt;/strong&gt; or a &lt;strong&gt;bool?&lt;/strong&gt; property of a ViewModel doesn&amp;rsquo;t always seem to display the correct ON or OFF value? It may be you have encountered a rather subtle bug in the ToggleButton control.&lt;/p&gt;
&lt;p&gt;I have just been developing an app using MVVM and noticed a problem with the ToggleSwitch control from the Silverlight Toolkit for Windows Phone (November 2011 release).&amp;nbsp; I noticed that a ToggleSwitch that had its IsChecked property databound to a ViewModel class did not update the ToggleSwitch UI as expected &amp;ndash; but only when the bound property on the viewmodel is changed from true to false and only when the ToggleSwitch is not visible. Puzzled? Let me explain&amp;hellip;&lt;/p&gt;
&lt;p&gt;This can be easily demonstrated by a slight variant on the well-known Databound App that you can create using the standard project templates. I added an additional property to the ItemViewModel class so alongside the existing LineOne, LineTwo and LineThree properties, it now has an additional property of type &lt;strong&gt;bool?&lt;/strong&gt; called &lt;strong&gt;IsActive&lt;/strong&gt;:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:#0000ff;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ItemViewModel &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;INotifyPropertyChanged
&lt;/span&gt;{
&lt;span style="color:#0000ff;"&gt;    public string &lt;/span&gt;LineOne  { ... }

&lt;span style="color:#0000ff;"&gt;    public string &lt;/span&gt;LineTwo  { ... } 
&lt;span style="color:#0000ff;"&gt;    &lt;/span&gt;&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="color:#0000ff;"&gt;    public string &lt;/span&gt;LineThree { ... }
    
    &lt;span style="color:#0000ff;"&gt;private bool&lt;/span&gt;? _isActive;

    &lt;span style="color:#0000ff;"&gt;public bool&lt;/span&gt;? IsActive
    {
        &lt;span style="color:#0000ff;"&gt;get
        &lt;/span&gt;{
            &lt;span style="color:#0000ff;"&gt;return &lt;/span&gt;_isActive;
        }
        &lt;span style="color:#0000ff;"&gt;set
        &lt;/span&gt;{
            &lt;span style="color:#0000ff;"&gt;if &lt;/span&gt;(&lt;span style="color:#0000ff;"&gt;value &lt;/span&gt;!= _isActive)
            {
                _isActive = &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;;
                NotifyPropertyChanged(&lt;span style="color:#a31515;"&gt;&amp;quot;IsActive&amp;quot;&lt;/span&gt;);
            }
        }
    }

    &lt;span style="color:#0000ff;"&gt;public event &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;PropertyChangedEventHandler &lt;/span&gt;PropertyChanged;
    ...&lt;/pre&gt;
&lt;pre class="code"&gt;}&lt;/pre&gt;
&lt;p&gt;Next, I changed the DataTemplate for the ListBox on the main page so that it displays a ToggleSwitch with its IsChecked property databound to the new IsActive property of my ViewModel. For interest, I also added a Checkbox databound in a similar way because ToggleSwitch inherits from CheckBox and I wanted to see if the problem existed with the CheckBox as well. So the DataTemplate looks like this:&lt;/p&gt;
&lt;pre class="code"&gt;            &lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListBox &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;x&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Name&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;MainListBox&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Margin&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;0,0,-12,0&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;ItemsSource&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Items&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;SelectionChanged&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;MainListBox_SelectionChanged&amp;quot;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListBox.ItemTemplate&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;
                    &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DataTemplate&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;
                      &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Margin&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;0,0,0,17&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Width&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;432&amp;quot;&amp;gt;
                          &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBlock &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Text&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;LineOne&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;TextWrapping&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Wrap&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Style&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;PhoneTextExtraLargeStyle&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;}&amp;quot;/&amp;gt;
                          &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBlock &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Text&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;LineTwo&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;TextWrapping&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Wrap&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Margin&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;12,-6,12,0&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Style&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;PhoneTextSubtleStyle&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;}&amp;quot;/&amp;gt;
                          &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;CheckBox  &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Content&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Is Active&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;IsChecked&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;IsActive&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;IsEnabled&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;False&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Margin&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;0,-6,0,0&amp;quot;/&amp;gt;
                          &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;toolkit&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ToggleSwitch &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Margin&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;0,-36,0,0&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;IsChecked&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;IsActive&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;IsEnabled&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;False&amp;quot;/&amp;gt;
                        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;
                    &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DataTemplate&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListBox.ItemTemplate&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;ListBox&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Next i updated the code in the constructor of &lt;strong&gt;MainViewModel&lt;/strong&gt; so that it sets &amp;lsquo;runtime one&amp;rsquo; &lt;strong&gt;IsActive&lt;/strong&gt; to &lt;strong&gt;false&lt;/strong&gt;, &amp;lsquo;runtime two&amp;rsquo; &lt;strong&gt;IsActive&lt;/strong&gt; to &lt;strong&gt;true&lt;/strong&gt; and &amp;lsquo;runtime three&amp;rsquo; &lt;strong&gt;IsActive&lt;/strong&gt; to &lt;strong&gt;null&lt;/strong&gt;. When running the List looks like this, just as you would expect:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ToggleMainList_5F00_3A62CE52.png"&gt;&lt;img height="512" width="284" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ToggleMainList_5F00_thumb_5F00_4969875F.png" alt="ToggleMainList" border="0" title="ToggleMainList" style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The CheckBox and the ToggleSwitch controls in the template display the UI you would expect, Unchecked/Off for runtime one, Checked/On for runtime two and Indeterminate/Off for Runtime three.&lt;/p&gt;
&lt;p&gt;When you tap on an item in the ListBox, the standard Databound App navigates to &lt;strong&gt;DetailsPage.xaml&lt;/strong&gt;, and in my version, I have added a ToggleSwitch to that page with its IsChecked property databound to the IsActive property.&amp;nbsp; I also added an ApplicationBar to that page with an &amp;lsquo;Edit&amp;rsquo; button on it that when pressed navigates to another page called &lt;strong&gt;EditDetailsPage.xaml&lt;/strong&gt; which is similar to DetailsPage.xaml but uses two-way databinding to allow you to edit the fields of the underlying data item. It looks like this:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ToggleEdit_5F00_4CBAF93A.png"&gt;&lt;img height="517" width="287" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ToggleEdit_5F00_thumb_5F00_00BF72C1.png" alt="ToggleEdit" border="0" title="ToggleEdit" style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[I won&amp;rsquo;t go into the simple code behind this &amp;ndash; download the sample code that accompanies this post to see how this is implemented &lt;img src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/wlEmoticon_2D00_smile_5F00_3D27C19E.png" alt="Smile" class="wlEmoticon wlEmoticon-smile" style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" /&gt;].&lt;/p&gt;
&lt;p&gt;Remember that when the app starts up, the &amp;lsquo;runtime one&amp;rsquo; object has &lt;strong&gt;IsActive&lt;/strong&gt; set to &lt;strong&gt;false&lt;/strong&gt;, so the checkbox and ToggleSwitch in the full list on MainPage.xaml are &amp;lsquo;Off&amp;rsquo;. If you then tap on the Runtime One record in the ListBox, the app navigates to DetailsPage.xaml to show the details of that record. If I then tap on the application bar Edit button, the app navigates to EditDetailsPage.xaml. On that edit page, I have checked the CheckBox so thanks to two-way databinding, the &lt;strong&gt;IsActive&lt;/strong&gt; property of &amp;lsquo;runtime one&amp;rsquo; is now set to &lt;strong&gt;true&lt;/strong&gt;. So of course, as we navigate back through the pages, the ToggleSwitch and Checkbox controls that are bound to that property will be checked, correct?&lt;/p&gt;
&lt;p&gt;Correct. Everything is as it should be:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ToggleEditCorrect1_5F00_436E982C.png"&gt;&lt;img height="484" width="268" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ToggleEditCorrect1_5F00_thumb_5F00_7EFE811F.png" alt="ToggleEditCorrect1" border="0" title="ToggleEditCorrect1" style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ToggleEditCorrect2_5F00_26E1807F.png"&gt;&lt;img height="484" width="268" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ToggleEditCorrect2_5F00_thumb_5F00_3B37203D.png" alt="ToggleEditCorrect2" border="0" title="ToggleEditCorrect2" style="background-image:none;border-bottom:0px;border-left:0px;margin:0px 0px 0px 20px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So, no problem there. The &lt;strong&gt;ToggleSwitch&lt;/strong&gt; on &lt;strong&gt;DetailsPage.xaml&lt;/strong&gt; is correctly shown as &amp;lsquo;&lt;strong&gt;On&lt;/strong&gt;&amp;rsquo; (the left hand screenshot), and on &lt;strong&gt;MainPage.xaml&lt;/strong&gt;, the CheckBox and the ToggleSwitch in the list for runtime one have correctly detected that &lt;strong&gt;IsActive&lt;/strong&gt; property is now true, so are showing as &lt;strong&gt;Checked&lt;/strong&gt; and &lt;strong&gt;On&lt;/strong&gt; respectively.&lt;/p&gt;
&lt;p&gt;Now we&amp;lsquo;ll reverse that and set &lt;strong&gt;IsActive&lt;/strong&gt; to false again. So tap on runtime one in the list and we navigate to the &lt;strong&gt;DetailsPage.xaml&lt;/strong&gt;, then tap on the edit button in the appbar and we navigate to &lt;strong&gt;EditDetailspage.xaml&lt;/strong&gt;. Tap the checkbox to clear it and then tap &lt;strong&gt;Save&lt;/strong&gt;. This is where things go wrong &lt;img src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/wlEmoticon_2D00_surprisedsmile_5F00_53E64780.png" alt="Surprised smile" class="wlEmoticon wlEmoticon-surprisedsmile" style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" /&gt;. The &lt;strong&gt;ToggleSwitch&lt;/strong&gt; controls both on &lt;strong&gt;DetailsPage.xaml&lt;/strong&gt; and in the DataTemplate for the ListBox on &lt;strong&gt;MainPage.xaml&lt;/strong&gt; do &lt;strong&gt;&lt;span style="text-decoration:underline;"&gt;not&lt;/span&gt;&lt;/strong&gt; pick up the fact that &lt;strong&gt;IsActive&lt;/strong&gt; is now &lt;strong&gt;false&lt;/strong&gt; &amp;ndash; though the &lt;strong&gt;CheckBox&lt;/strong&gt; controls *&lt;span style="text-decoration:underline;"&gt;&lt;strong&gt;do&lt;/strong&gt;&lt;/span&gt;* pick it up and display &lt;strong&gt;unchecked&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ToggleEditWrong1_5F00_1E6D855B.png"&gt;&lt;img height="484" width="268" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ToggleEditWrong1_5F00_thumb_5F00_604444DC.png" alt="ToggleEditWrong1" border="0" title="ToggleEditWrong1" style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ToggleEditWrong2_5F00_158D5742.png"&gt;&lt;img height="484" width="268" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ToggleEditWrong2_5F00_thumb_5F00_5EEF8630.png" alt="ToggleEditWrong2" border="0" title="ToggleEditWrong2" style="background-image:none;border-bottom:0px;border-left:0px;margin:0px 0px 0px 20px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ToggleEditWrong3_5F00_34BFD848.png"&gt;&lt;img height="484" width="268" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/ToggleEditWrong3_5F00_thumb_5F00_693084C3.png" alt="ToggleEditWrong3" border="0" title="ToggleEditWrong3" style="background-image:none;border-bottom:0px;border-left:0px;margin:0px 0px 0px 20px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As you can see, the Checkbox has been cleared on the first edit screen &amp;ndash; this causes the &lt;strong&gt;IsActive&lt;/strong&gt; property of the viewmodel to be set to &lt;strong&gt;false&lt;/strong&gt;. Pressing the save button on that screen causes a navigation back to the View Details screen (middle screen shot) and as you can see, the ToggleSwitch on that screen hasn&amp;rsquo;t picked up the fact that the viewmodel has changed since it is still set to On. Another press of the Back key puts you back on the main page, where the ListBox displays both a CheckBox and a ToggleSwitch databound to the IsActive property and here the CheckBox is unset but the ToggleSwitch is still On.&lt;/p&gt;
&lt;p&gt;Note that this problem only occurs when the databound ToggleSwitches are not visible. When the IsActive property of the viewmodel class is set, it fires PropertyChanged events in the normal way. In Windows Phone, as you navigate through pages, the control objects that are on the parent screens (such as MainPage.xaml and DetailsPage.xaml in this example) stay in memory but are not rendered to the screen. Although the TextBox and CheckBox controls respond correctly to changes in a databound property of an underlying viewmodel class, the ToggleSwitch does not &amp;ndash; well at least not when a bool? type is changed from true to false!&lt;/p&gt;
&lt;p&gt;In the download for this post, I&amp;rsquo;ve included another simple project that shows that there is no problem with a databound ToggleButton as long as it is visible.&lt;/p&gt;
&lt;p&gt;The workaround for this? You have to force the ToggleButton to refresh its binding and this is best done in OnNavigatedTo. For example, in OnNavigatedTo on DetailsPage.xaml, add code such as:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:#0000ff;"&gt;protected override void &lt;/span&gt;OnNavigatedTo(&lt;span style="color:#2b91af;"&gt;NavigationEventArgs &lt;/span&gt;e)
{

    &lt;span style="color:#0000ff;"&gt;...&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="code"&gt;&lt;span style="color:#0000ff;"&gt;&lt;/span&gt;
    &lt;span style="color:#008000;"&gt;// Force the ToggleButton to refresh its binding
    &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ItemViewModel &lt;/span&gt;vm = &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.DataContext &lt;span style="color:#0000ff;"&gt;as &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ItemViewModel&lt;/span&gt;;
    &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.ToggleSwitch1.IsChecked = vm.IsActive;
}&lt;/pre&gt;
&lt;p&gt;For the ListBox on&amp;nbsp; MainPage.xaml, you could use a blunt stick approach and simply toggle the setting of the ItemsSource to force it to renew all its bindings:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:#0000ff;"&gt;protected override void &lt;/span&gt;OnNavigatedTo(System.Windows.Navigation.&lt;span style="color:#2b91af;"&gt;NavigationEventArgs &lt;/span&gt;e)
{
    &lt;span style="color:#0000ff;"&gt;base&lt;/span&gt;.OnNavigatedTo(e);

&lt;span style="color:#008000;"&gt;    // Toggle the ItemsSource setting to force the ToggleSwitches to rebind
    &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.MainListBox.ItemsSource = &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;;
    &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.MainListBox.ItemsSource = &lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;.ViewModel.Items;
}&lt;/pre&gt;
&lt;p&gt;It&amp;rsquo;s ugly but effective. More elegant solutions would be possible using the VisualTreeHelper to identify the ToggleButton instances and to refresh them individually, but I leave that as an exercise for the reader &lt;img src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/wlEmoticon_2D00_smile_5F00_3D27C19E.png" alt="Smile" class="wlEmoticon wlEmoticon-smile" style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=430" width="1" height="1"&gt;</description><enclosure url="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.00.04.30/DataBoundToggleSwitch.zip" length="1167252" type="application/x-zip-compressed" /><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Windows+Phone+7/default.aspx">Windows Phone 7</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/wp7dev/default.aspx">wp7dev</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/_2300_wp7dev/default.aspx">#wp7dev</category></item><item><title>Windows Phone LINQ to SQL and Data Virtualization</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2011/12/14/windows-phone-linq-to-sql-and-data-virtualization.aspx</link><pubDate>Wed, 14 Dec 2011 12:05:01 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:423</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>5</slash:comments><description>&lt;h1&gt;How to work with large tables in LINQ to SQL on Windows Phone&lt;/h1&gt; &lt;h2&gt;Introduction to Data Virtualization&lt;/h2&gt; &lt;p&gt;Data Virtualization is a technique you use to expose a subset of the data from a large data collection so that only the actual data you need is fetched into memory. To implement data virtualization, you take your data collection which could contain any number of rows – even a million rows or more! – and you create a custom class for your virtualized data collection that implements IList&amp;lt;T&amp;gt; and acts as a facade to the underlying data collection.&lt;/p&gt; &lt;p&gt;IList&amp;lt;T&amp;gt; has a great many methods, but fortunately the only methods you have to implement are:&lt;/p&gt; &lt;ul&gt; &lt;li&gt; &lt;p&gt;&lt;span style="color:blue;"&gt;public int &lt;/span&gt;Count &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;pre class="code"&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="color:#2b91af;"&gt;T IList&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;T&lt;/span&gt;&amp;gt;.&lt;span style="color:blue;"&gt;this&lt;/span&gt;[&lt;span style="color:blue;"&gt;int &lt;/span&gt;index]&lt;/li&gt;&lt;/ul&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;The count property just returns the number of items in the underlying data collection, while the second is just the indexer and allows you to retrieve the ‘nth’ item from the underlying collection. The rest of the methods of IList&amp;lt;T&amp;gt; must of course be implemented in your virtualized data collection class, but you can just throw the NotImplemented exception – in most usages, they will not be called. The only other method of IList&amp;lt;T&amp;gt; that you might choose to implement is &lt;strong&gt;&lt;span style="color:blue;"&gt;public int &lt;/span&gt;IndexOf(&lt;span style="color:#2b91af;"&gt;T&lt;/span&gt;item)&lt;/strong&gt; which returns the position of an item in the underlying collection. This becomes useful when you want to do lookups in the collection.&lt;/p&gt;
&lt;p&gt;In Windows Phone apps, this is beneficial when you want to display a long list of items in a &lt;strong&gt;ListBox&lt;/strong&gt;. Just set your ListBox &lt;strong&gt;ItemsSource&lt;/strong&gt; property to an instance of your virtualized data collection class, and the ListBox will only fetch the visible items and a few either side (to assist with scrolling up and down the list). You can read more about this technique in Shawn Oster’s blog: &lt;a href="http://shawnoster.com/blog/post/Improving-ListBox-Performance-in-Silverlight-for-Windows-Phone-7-Data-Virtualization.aspx"&gt;Improving ListBox Performance in Silverlight for Windows Phone 7: Data Virtualization&lt;/a&gt; or in Peter Torr’s blog: &lt;a href="http://blogs.msdn.com/b/ptorr/archive/2010/08/16/virtualizing-data-in-windows-phone-7-silverlight-applications.aspx"&gt;Virtualizing Data in Windows Phone 7 Silverlight Applications&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Data Virtualization with LINQ to SQL&lt;/h2&gt;
&lt;p&gt;So, on to the purpose of this post. I wondered how to implement data virtualization using LINQ to SQL in Windows Phone Mango. For my test database, I created a database with a single table in it which could be used in a dictionary application. It has 200000 entries in it, and the the Word table looks like this:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/Table_2D00_design_5F00_79704A82.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="Table design" border="0" alt="Table design" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/Table_2D00_design_5F00_thumb_5F00_52FE416A.png" width="472" height="407" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Ignore the Sequence column for now – we’ll come back to that at the end. The &lt;strong&gt;WordTxt&lt;/strong&gt; column is up to 128 characters in length and is the Primary Key, while the &lt;strong&gt;WordDescription&lt;/strong&gt; column is up to 1024 characters and holds the description of the word. I’ve filled the table with randomly generated data (using a contorted process – see footnote &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/wlEmoticon_2D00_smile_5F00_6E30EC29.png" /&gt; ) and now we can try to bind the data in this table to a ListBox.&lt;/p&gt;
&lt;p&gt;You can &lt;a href="https://skydrive.live.com/redir.aspx?cid=b36de4dd5a9179a1&amp;amp;resid=B36DE4DD5A9179A1!1334&amp;amp;parid=B36DE4DD5A9179A1!1333"&gt;download the sample project here&lt;/a&gt; (it’s nearly 50MB since it contains a database that is 107MB when decompressed). Compile the project and deploy it onto your target emulator or device.&lt;/p&gt;
&lt;p&gt;IMPORTANT: The database is included in the project, but its Build Action is set to ‘None’ and Copy to Output Directory set to ‘Do not copy’ – so you’ll have to manually copy the database onto the target. I’ve done it this way because if you include the database as Content it takes around 5 minutes to build and deploy the app which is tedious when you’re playing with the code. So to deploy the database, either change its Build Action to Embedded Resource and then go away and have a cup of tea while it’s deploying, or use the Isolated Storage Explorer Tool to copy it to the target, or better still the nice tools at &lt;a href="http://wptools.codeplex.com"&gt;http://wptools.codeplex.com&lt;/a&gt; .&lt;/p&gt;
&lt;p&gt;In the project, in the App.xaml.cs I initialize the data context appropriately for a read only database:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DictionaryDatabaseContext &lt;/span&gt;DbDC;

&lt;span style="color:green;"&gt;// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
&lt;/span&gt;&lt;span style="color:blue;"&gt;private void &lt;/span&gt;Application_Launching(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;LaunchingEventArgs &lt;/span&gt;e)
{
    DbDC = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DictionaryDatabaseContext&lt;/span&gt;(
        &lt;span style="color:#a31515;"&gt;&amp;quot;Data Source=isostore:/DictionaryDatabase.sdf;Max Database Size=180;File Mode=Read Only;&amp;quot;&lt;/span&gt;);
    DbDC.ObjectTrackingEnabled = &lt;span style="color:blue;"&gt;false&lt;/span&gt;;
}

&lt;span style="color:green;"&gt;// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
&lt;/span&gt;&lt;span style="color:blue;"&gt;private void &lt;/span&gt;Application_Activated(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;ActivatedEventArgs &lt;/span&gt;e)
{
    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(!e.IsApplicationInstancePreserved)
    {
        DbDC = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DictionaryDatabaseContext&lt;/span&gt;(
            &lt;span style="color:#a31515;"&gt;&amp;quot;Data Source=isostore:/DictionaryDatabase.sdf;Max Database Size=180;File Mode=Read Only;&amp;quot;&lt;/span&gt;);
        DbDC.ObjectTrackingEnabled = &lt;span style="color:blue;"&gt;false&lt;/span&gt;;
    }
}
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The main page just has four buttons on it which navigate to four different pages which use differing ways of binding to the data:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/L2S_2D00_Main_2D00_page_5F00_3198ED8C.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="L2S Main page" border="0" alt="L2S Main page" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/L2S_2D00_Main_2D00_page_5F00_thumb_5F00_5354A050.png" width="184" height="331" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Every page has a ListBox on it which uses the following DataTemplate to format the display of items in the list:&lt;/p&gt;&lt;pre class="code"&gt;        &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DataTemplate &lt;/span&gt;&lt;span style="color:red;"&gt;x&lt;/span&gt;&lt;span style="color:blue;"&gt;:&lt;/span&gt;&lt;span style="color:red;"&gt;Key&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;WordTemplate&amp;quot;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBlock &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:red;"&gt;WordTxt&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot; 
                           &lt;/span&gt;&lt;span style="color:red;"&gt;Style&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:red;"&gt;PhoneTextAccentStyle&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot;/&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;TextBlock &lt;/span&gt;&lt;span style="color:red;"&gt;Text&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Binding &lt;/span&gt;&lt;span style="color:red;"&gt;WordDescription&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot; 
                           &lt;/span&gt;&lt;span style="color:red;"&gt;Style&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StaticResource &lt;/span&gt;&lt;span style="color:red;"&gt;PhoneTextSmallStyle&lt;/span&gt;&lt;span style="color:blue;"&gt;}&amp;quot; 
                           &lt;/span&gt;&lt;span style="color:red;"&gt;Width&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;436&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;TextWrapping&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;Wrap&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Margin&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;12,0,12,12&amp;quot; &lt;/span&gt;&lt;span style="color:red;"&gt;Height&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;75&amp;quot;/&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;StackPanel&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;DataTemplate&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;h3&gt;Option 1: Bind directly to the database table&lt;/h3&gt;
&lt;p&gt;This is just to prove the point. The ‘Load All’ button navigates to a page that just binds the ListBox directly to the database table:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;using &lt;/span&gt;Microsoft.Phone.Controls;

&lt;span style="color:blue;"&gt;namespace &lt;/span&gt;LargeDBAppSample.Views
{
    &lt;span style="color:blue;"&gt;public partial class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;LoadAllPage &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;PhoneApplicationPage
    &lt;/span&gt;{
        &lt;span style="color:blue;"&gt;public &lt;/span&gt;LoadAllPage()
        {
            InitializeComponent();
            &lt;span style="color:blue;"&gt;this&lt;/span&gt;.Loaded += ((s, e) =&amp;gt;
            {
                &lt;span style="color:#2b91af;"&gt;DictionaryDatabaseContext &lt;/span&gt;dc = ((&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;)&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;.Current).DbDC;
                listBox1.ItemsSource = dc.Words;
            }
           );
        }
    }
}
&lt;/pre&gt;
&lt;p&gt;When you try this option, the result is predictable. I’m using Peter Torr’s very helpful &lt;a href="http://blogs.msdn.com/b/ptorr/archive/2010/10/30/that-memory-thing-i-promised-you.aspx"&gt;MemoryDiagnosticsHelper&lt;/a&gt; which writes the memory usage alongside the Framerate counters. This throws a debug assert when memory exceeds 90MB, and in this case we hit 104MB:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/L2S_2D00_LoadAll_5F00_4A18650F.png"&gt;&lt;img style="background-image:none;border-right-width:0px;margin:0px 0px 0px 20px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="L2S LoadAll" border="0" alt="L2S LoadAll" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/L2S_2D00_LoadAll_5F00_thumb_5F00_6A8F7EF4.png" width="208" height="375" /&gt;&lt;/a&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/MemoryExceeded_5F00_4712DA8F.png"&gt;&lt;img style="background-image:none;border-right-width:0px;margin:0px 0px 20px 20px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="MemoryExceeded" border="0" alt="MemoryExceeded" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/MemoryExceeded_5F00_thumb_5F00_1AF5DD9E.png" width="113" height="284" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;Option 2: Data Virtualization – Bad Implementation&lt;/h3&gt;
&lt;p&gt;The second button on the main page takes you to a page that uses data virtualization. In this case, we also have a textbox where the user can enter a search string – because let’s face it, a ListBox that contains 200000 items is not going to give a good user experience. Scroll down to the bottom to find the ‘Y’s?? – I don’t think so &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/wlEmoticon_2D00_smile_5F00_6E30EC29.png" /&gt;.&lt;/p&gt;
&lt;p&gt;So the code for the page here looks like this:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public partial class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;BadDataVirtualizationPage &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;PhoneApplicationPage
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;public &lt;/span&gt;BadDataVirtualizationPage()
    {
        InitializeComponent();

        &lt;span style="color:blue;"&gt;this&lt;/span&gt;.Loaded += ((s, e) =&amp;gt;
            {
                listBox1.ItemsSource = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;BadVirtualizedDataModel&lt;/span&gt;();
            }
        );
    }

    &lt;span style="color:blue;"&gt;private void &lt;/span&gt;txtSearch_TextChanged(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;TextChangedEventArgs &lt;/span&gt;e)
    {
        &lt;span style="color:#2b91af;"&gt;DictionaryDatabaseContext &lt;/span&gt;dc = ((&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;)&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;.Current).DbDC;

        &lt;span style="color:blue;"&gt;var &lt;/span&gt;words = &lt;span style="color:blue;"&gt;from &lt;/span&gt;w &lt;span style="color:blue;"&gt;in &lt;/span&gt;dc.Words
                    &lt;span style="color:blue;"&gt;where &lt;/span&gt;w.WordTxt.StartsWith(txtSearch.Text)
                    &lt;span style="color:blue;"&gt;select &lt;/span&gt;w;

        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(words.Count() == 0)
            &lt;span style="color:#2b91af;"&gt;MessageBox&lt;/span&gt;.Show(&lt;span style="color:#a31515;"&gt;&amp;quot;No matches&amp;quot;&lt;/span&gt;);
        &lt;span style="color:blue;"&gt;else
            &lt;/span&gt;listBox1.ScrollIntoView(words.First&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt;());
    }
}&lt;/pre&gt;&lt;pre class="code"&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;As you can see, the ListBox is bound to an instance of BadVirtualizedDataModel. Why is it bad? I’ll explain shortly….&lt;/p&gt;
&lt;p&gt;The class implements IList&amp;lt;Word&amp;gt; and as you can see below, it returns the count (which is cached since for some reason the ListBox asks for it multiple times). The indexer property uses some LINQ to SQL to fetch the item in the table at a particular index, and I write the time taken to the Debug Output window. The whole class looks like this:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;using &lt;/span&gt;System;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Linq;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Collections;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Collections.Generic;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Diagnostics;

&lt;span style="color:blue;"&gt;namespace &lt;/span&gt;LargeDBAppSample.Model
{
    &lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;BadVirtualizedDataModel &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt;
    {
        &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DictionaryDatabaseContext &lt;/span&gt;dc = ((&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;)&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;.Current).DbDC;
        &lt;span style="color:blue;"&gt;int&lt;/span&gt;? cachedCount = &lt;span style="color:blue;"&gt;null&lt;/span&gt;;

        &lt;span style="color:blue;"&gt;public int &lt;/span&gt;Count
        {
            &lt;span style="color:blue;"&gt;get &lt;/span&gt;{
                &lt;span style="color:blue;"&gt;if &lt;/span&gt;(!cachedCount.HasValue)
                {
                    &lt;span style="color:blue;"&gt;var &lt;/span&gt;wordcount = dc.Words.Count();
                    cachedCount = wordcount;
                }
                &lt;span style="color:blue;"&gt;return &lt;/span&gt;cachedCount.Value; 
            }
        }

        &lt;span style="color:#2b91af;"&gt;Word IList&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt;.&lt;span style="color:blue;"&gt;this&lt;/span&gt;[&lt;span style="color:blue;"&gt;int &lt;/span&gt;index]
        {
            &lt;span style="color:blue;"&gt;get
            &lt;/span&gt;{
                &lt;span style="color:#2b91af;"&gt;Stopwatch &lt;/span&gt;sw = &lt;span style="color:#2b91af;"&gt;Stopwatch&lt;/span&gt;.StartNew();

                &lt;span style="color:blue;"&gt;var &lt;/span&gt;word = (&lt;span style="color:blue;"&gt;from &lt;/span&gt;w &lt;span style="color:blue;"&gt;in &lt;/span&gt;dc.Words
                            &lt;span style="color:blue;"&gt;orderby &lt;/span&gt;w.WordTxt
                            &lt;span style="color:blue;"&gt;select &lt;/span&gt;w).Skip(index).Take(1).First();
                
                &lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Fetched {0} in {1}ms&amp;quot;&lt;/span&gt;, &lt;span style="color:blue;"&gt;new object&lt;/span&gt;[] { index, sw.ElapsedMilliseconds });
                &lt;span style="color:blue;"&gt;return &lt;/span&gt;word;
            }
            &lt;span style="color:blue;"&gt;set
            &lt;/span&gt;{
                &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
            }
        }

        &lt;span style="color:blue;"&gt;public int &lt;/span&gt;IndexOf(&lt;span style="color:#2b91af;"&gt;Word &lt;/span&gt;item)
        {
            &lt;span style="color:#2b91af;"&gt;Stopwatch &lt;/span&gt;sw = &lt;span style="color:#2b91af;"&gt;Stopwatch&lt;/span&gt;.StartNew();

            &lt;span style="color:blue;"&gt;var &lt;/span&gt;matches = (&lt;span style="color:blue;"&gt;from &lt;/span&gt;w &lt;span style="color:blue;"&gt;in &lt;/span&gt;dc.Words &lt;span style="color:blue;"&gt;select &lt;/span&gt;w).AsEnumerable()
                .Select((matchItem, index) =&amp;gt; &lt;span style="color:blue;"&gt;new &lt;/span&gt;{ Item = matchItem, Position = index })
                            .Where(x =&amp;gt; x.Item.WordTxt == item.WordTxt);

            &lt;span style="color:blue;"&gt;int &lt;/span&gt;position = matches.First().Position;

            &lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Found position of {0} in {1}ms&amp;quot;&lt;/span&gt;, &lt;span style="color:blue;"&gt;new object&lt;/span&gt;[] { item.WordTxt, sw.ElapsedMilliseconds });

            &lt;span style="color:blue;"&gt;return &lt;/span&gt;position;
        }

        &lt;span style="color:blue;"&gt;#region &lt;/span&gt;NotRequired

        &lt;span style="color:blue;"&gt;public int &lt;/span&gt;Add(&lt;span style="color:blue;"&gt;object &lt;/span&gt;value)
        {
            &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
        }

        &lt;span style="color:blue;"&gt;public void &lt;/span&gt;Clear()
        {
            &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
        }

        &lt;span style="color:blue;"&gt;public bool &lt;/span&gt;Contains(&lt;span style="color:blue;"&gt;object &lt;/span&gt;value)
        {
            &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
        }

        &lt;span style="color:blue;"&gt;public void &lt;/span&gt;Insert(&lt;span style="color:blue;"&gt;int &lt;/span&gt;index, &lt;span style="color:blue;"&gt;object &lt;/span&gt;value)
        {
            &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
        }

        &lt;span style="color:blue;"&gt;public bool &lt;/span&gt;IsFixedSize
        {
            &lt;span style="color:blue;"&gt;get &lt;/span&gt;{ &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;(); }
        }

        &lt;span style="color:blue;"&gt;public bool &lt;/span&gt;IsReadOnly
        {
            &lt;span style="color:blue;"&gt;get &lt;/span&gt;{ &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;(); }
        }

        &lt;span style="color:blue;"&gt;public void &lt;/span&gt;RemoveAt(&lt;span style="color:blue;"&gt;int &lt;/span&gt;index)
        {
            &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
        }

        &lt;span style="color:blue;"&gt;public bool &lt;/span&gt;IsSynchronized
        {
            &lt;span style="color:blue;"&gt;get &lt;/span&gt;{ &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;(); }
        }

        &lt;span style="color:blue;"&gt;public object &lt;/span&gt;SyncRoot
        {
            &lt;span style="color:blue;"&gt;get &lt;/span&gt;{ &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;(); }
        }

        &lt;span style="color:blue;"&gt;public void &lt;/span&gt;Insert(&lt;span style="color:blue;"&gt;int &lt;/span&gt;index, &lt;span style="color:#2b91af;"&gt;Word &lt;/span&gt;item)
        {
            &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
        }

        &lt;span style="color:blue;"&gt;public void &lt;/span&gt;Add(&lt;span style="color:#2b91af;"&gt;Word &lt;/span&gt;item)
        {
            &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
        }

        &lt;span style="color:blue;"&gt;public bool &lt;/span&gt;Contains(&lt;span style="color:#2b91af;"&gt;Word &lt;/span&gt;item)
        {
            &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
        }

        &lt;span style="color:blue;"&gt;public void &lt;/span&gt;CopyTo(&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;[] array, &lt;span style="color:blue;"&gt;int &lt;/span&gt;arrayIndex)
        {
            &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
        }

        &lt;span style="color:blue;"&gt;public bool &lt;/span&gt;Remove(&lt;span style="color:#2b91af;"&gt;Word &lt;/span&gt;item)
        {
            &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
        }

        &lt;span style="color:blue;"&gt;public &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IEnumerator &lt;/span&gt;GetEnumerator()
        {
            &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
        }

        &lt;span style="color:#2b91af;"&gt;IEnumerator&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt; &lt;span style="color:#2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt;.GetEnumerator()
        {
            &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
        }

        &lt;span style="color:blue;"&gt;#endregion
    &lt;/span&gt;}
}

&lt;/pre&gt;
&lt;p&gt;So when you run this, first impressions are very favorable. The list appears in no time at all, scrolling up and down the list is really fast, and memory usage is only about 24MB. Looks great!&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/L2S_2D00_Bad_5F00_38F3EB92.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="L2S Bad" border="0" alt="L2S Bad" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/L2S_2D00_Bad_5F00_thumb_5F00_496B9AE6.png" width="587" height="489" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;However, everything is not as good as it seems. This is illustrated if you type a letter from later in the alphabet, such as ‘t’ into the Search box. Look at what is reported in the output window now:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/L2S_2D00_Bad_2D00_Search_5F00_4816DC3A.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="L2S Bad Search" border="0" alt="L2S Bad Search" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/L2S_2D00_Bad_2D00_Search_5F00_thumb_5F00_3C1199AE.png" width="677" height="492" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;There are two lines starting ‘Found Position…’ each taking over 4.3 seconds, and further down the ‘Fetched…’ lines report how long it takes to get an item from the collection at a particular index are now taking over 370ms each. From this point on, scroll performance of the ListBox is terrible. What is going on?&lt;/p&gt;
&lt;p&gt;The code that is executing here is firstly the TextChanged event handler finds the first word in the table that begins with the letters entered into the Search textbox:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;private void &lt;/span&gt;txtSearch_TextChanged(&lt;span style="color:blue;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;TextChangedEventArgs &lt;/span&gt;e)
{
    &lt;span style="color:#2b91af;"&gt;DictionaryDatabaseContext &lt;/span&gt;dc = ((&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;)&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;.Current).DbDC;

    &lt;span style="color:blue;"&gt;var &lt;/span&gt;words = &lt;span style="color:blue;"&gt;from &lt;/span&gt;w &lt;span style="color:blue;"&gt;in &lt;/span&gt;dc.Words
                &lt;span style="color:blue;"&gt;where &lt;/span&gt;w.WordTxt.StartsWith(txtSearch.Text)
                &lt;span style="color:blue;"&gt;select &lt;/span&gt;w;

    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(words.Count() == 0)
        &lt;span style="color:#2b91af;"&gt;MessageBox&lt;/span&gt;.Show(&lt;span style="color:#a31515;"&gt;&amp;quot;No matches&amp;quot;&lt;/span&gt;);
    &lt;span style="color:blue;"&gt;else
        &lt;/span&gt;listBox1.ScrollIntoView(words.First&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt;());
}
&lt;/pre&gt;
&lt;p&gt;The lookup is really fast because it is doing a lookup on the WordTxt field which is the primary key. &lt;/p&gt;
&lt;p&gt;However, once we have found our word, we call the ListBox.ScrollIntoView(object) method to cause the ListBox to scroll to display the first matching word. The way the ListBox does this is to first call the IndexOf(Word item) method of the data collection to find the index in the collection of the desired item (which it does twice for some reason), and then to call the indexer as normal to pull the required items out of the collection. It is the IndexOf() method that is reporting the 4.3 second search times and the indexer that is reporting times of over 370ms.&lt;/p&gt;
&lt;p&gt;The problem here is that an index in a SQL Server Compact Edition database (the underlying database for LINQ to SQL on Windows Phone) is not optimised for random access. There is no efficient way of getting the 109,456th item out of an index. The code used in the indexer is actually an adaptation of what is in the MSDN Windows Phone documentation, topic &lt;a href="http://msdn.microsoft.com/en-us/library/hh286406(v=VS.92).aspx"&gt;Local Database Best Practices for Windows Phone&lt;/a&gt;, which states:&lt;/p&gt;
&lt;h4&gt;&lt;em&gt;&lt;font style="font-weight:bold;"&gt;Use of Data Virtualization and Skip/Take&lt;/font&gt;&lt;/em&gt;&lt;/h4&gt;
&lt;p&gt;&lt;em&gt;With ListBox controls, you can use the Skip and Take methods to enable fetching of the appropriate batches of items as the user scrolls through the list. For more information about enabling data virtualization on data-bound ListBox controls, see &lt;/em&gt;&lt;a href="http://shawnoster.com/blog/post/Improving-ListBox-Performance-in-Silverlight-for-Windows-Phone-7-Data-Virtualization.aspx"&gt;&lt;em&gt;Improving ListBox Performance in Silverlight for Windows Phone 7: Data Virtualization&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt; 
&lt;p&gt;&lt;em&gt;Using the Skip and Take methods ensures that data will not be loaded from the database into memory until it is needed for display in the ListBox control. For example, the following code shows how to retrieve records 501 to 550 from the database.&lt;/em&gt; 
&lt;p&gt;&lt;a&gt;&lt;em&gt;C#&lt;/em&gt;&lt;/a&gt;&lt;pre&gt;&lt;em&gt;return
(from f in App.FeedsDB.Feeds                    
select f).Skip(500).Take(50);
&lt;/em&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;&amp;nbsp; &lt;p&gt;&lt;em&gt;Be&lt;/em&gt;&lt;em&gt;cause there is cost to performing this load operation as the user scrolls through the list, this technique should be limited to scenarios where the data set is large (greater than 150 items). For smaller data sets, loading the entire collection into memory and binding to it there is likely to yield better performance.&lt;/em&gt; 
&lt;p&gt;In actual fact, this best practice advice should be qualified by saying that it should not be used for collections of greater than perhaps 1000. What is actually happening here is that internally, the database engine is having to walk the record collection to implement the Skip(n) part of it. So while it is true to say that the skipped records are not loaded from the database into memory, the database engine is still having to do a great deal of work to identify the record(s) it does need to materialize into memory. 
&lt;p&gt;Our indexer looks like this: 
&lt;p&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;word = (&lt;span style="color:blue;"&gt;from &lt;/span&gt;w &lt;span style="color:blue;"&gt;in &lt;/span&gt;dc.Words &lt;span style="color:blue;"&gt;orderby &lt;/span&gt;w.WordTxt &lt;span style="color:blue;"&gt;select &lt;/span&gt;w).Skip(index).Take(1).First(); 
&lt;p&gt;However the real damage is being done by the IndexOf() method implementation:&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public int &lt;/span&gt;IndexOf(&lt;span style="color:#2b91af;"&gt;Word &lt;/span&gt;item)
{
    &lt;span style="color:#2b91af;"&gt;Stopwatch &lt;/span&gt;sw = &lt;span style="color:#2b91af;"&gt;Stopwatch&lt;/span&gt;.StartNew();

    &lt;span style="color:blue;"&gt;var &lt;/span&gt;matches = (&lt;span style="color:blue;"&gt;from &lt;/span&gt;w &lt;span style="color:blue;"&gt;in &lt;/span&gt;dc.Words &lt;span style="color:blue;"&gt;select &lt;/span&gt;w).AsEnumerable()
        .Select((matchItem, index) =&amp;gt; &lt;span style="color:blue;"&gt;new &lt;/span&gt;{ Item = matchItem, Position = index })
                    .Where(x =&amp;gt; x.Item.WordTxt == item.WordTxt);

    &lt;span style="color:blue;"&gt;int &lt;/span&gt;position = matches.First().Position;

    &lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Found position of {0} in {1}ms&amp;quot;&lt;/span&gt;, &lt;span style="color:blue;"&gt;new object&lt;/span&gt;[] { item.WordTxt, sw.ElapsedMilliseconds });

    &lt;span style="color:blue;"&gt;return &lt;/span&gt;position;
}
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This code was taken from a number of posts found in searches on the internet and while it works well enough, it also causes the database engine to work very hard to give us our result. The only good news with all of this is that memory utilisation remains low at 24MB but that’s no substitute for the terrible performance which makes this solution unusable.&lt;/p&gt;
&lt;h3&gt;Option 3: Data Virtualization – Better Implementation&lt;/h3&gt;
&lt;p&gt;The second and third buttons on the main page takes you to two different pages that use a workable implementation of data virtualization. Each shows a different solution to this problem of needing a random access index to a database table. The Good virtualization button takes you to a page that is the same as the one we have just used in the previous example, with the exception that when the page loads, the page calls the BeginInitialize() method on our GoodVirtualizedDataModel class which builds an in-memory lookup table to allow us to easily find the index of a word in the collection. In the form, the page initialization logic looks like this:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public partial class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;GoodDataVirtualizationPage &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;PhoneApplicationPage
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;public &lt;/span&gt;GoodDataVirtualizationPage()
    {
        InitializeComponent();

        &lt;span style="color:blue;"&gt;this&lt;/span&gt;.Loaded += ((s, e) =&amp;gt;
        {
            listBox1.ItemsSource = &lt;span style="color:blue;"&gt;null&lt;/span&gt;;

            &lt;span style="color:blue;"&gt;var &lt;/span&gt;vDM = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;GoodVirtualizedDataModel&lt;/span&gt;();
            vDM.InitializeCompleted += (ss, ee) =&amp;gt;
                {
                    listBox1.ItemsSource = vDM;
                    &lt;span style="color:#2b91af;"&gt;SystemTray&lt;/span&gt;.ProgressIndicator.IsVisible = &lt;span style="color:blue;"&gt;false&lt;/span&gt;;
                };

            vDM.BeginInitialize();
            &lt;span style="color:blue;"&gt;var &lt;/span&gt;pi = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ProgressIndicator&lt;/span&gt;();
            pi.IsIndeterminate = &lt;span style="color:blue;"&gt;true&lt;/span&gt;;
            pi.Text = &lt;span style="color:#a31515;"&gt;&amp;quot;Initializing..&amp;quot;&lt;/span&gt;;
            pi.IsVisible = &lt;span style="color:blue;"&gt;true&lt;/span&gt;;
            &lt;span style="color:#2b91af;"&gt;SystemTray&lt;/span&gt;.ProgressIndicator = pi;
        }
        );
    }
&lt;/pre&gt;
&lt;p&gt;…&lt;/p&gt;
&lt;p&gt;The GoodVirtualizedDataModel class has a private List&amp;lt;string&amp;gt; field called inMemoryLookup and this is what is initialized by the BeginInitialize() method. That uses a BackgroundWorker to do the work on a background thread, but all it is doing is extracting just the WordTxt field (which is the primary key field) from every Word object in the database and inserting it into the List&amp;lt;string&amp;gt;:&lt;/p&gt;&lt;pre class="code"&gt;inMemoryLookup = (&lt;span style="color:blue;"&gt;from &lt;/span&gt;w &lt;span style="color:blue;"&gt;in &lt;/span&gt;dc.Words
                   &lt;span style="color:blue;"&gt;orderby &lt;/span&gt;w.WordTxt
                   &lt;span style="color:blue;"&gt;select &lt;/span&gt;w.WordTxt).ToList&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;gt;();
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Then in the indexer, instead of the costly .Skip(n).Take(1) operation, the code simply takes the index of the item that is passed in, uses it to fetch the object at that index from the inMemoryLookup collection and that gives it the primary key (the WordTxt) at that index which it uses to do an efficient primary key lookup for the required word:&lt;/p&gt;&lt;span style="color:blue;"&gt;&lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;Word IList&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt;.&lt;span style="color:blue;"&gt;this&lt;/span&gt;[&lt;span style="color:blue;"&gt;int &lt;/span&gt;index]
{
    &lt;span style="color:blue;"&gt;get
    &lt;/span&gt;{
        &lt;span style="color:blue;"&gt;var &lt;/span&gt;word = &lt;span style="color:blue;"&gt;from &lt;/span&gt;w &lt;span style="color:blue;"&gt;in &lt;/span&gt;dc.Words
                   &lt;span style="color:blue;"&gt;where &lt;/span&gt;w.WordTxt == inMemoryLookup[index]
                   &lt;span style="color:blue;"&gt;select &lt;/span&gt;w;
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;word.First&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt;();
    }
    &lt;span style="color:blue;"&gt;set
    &lt;/span&gt;{
        &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
    }
}
&lt;/pre&gt;&lt;/span&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In actual fact, as a further optimisation, instead of executing the same query every time the indexer Getter is called, the implementation in the sample uses a Compiled Query to avoid the overhead of the query processor doing the same query analysis on every call. This is the full class:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;using &lt;/span&gt;System;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Linq;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Collections;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Collections.Generic;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Diagnostics;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.ComponentModel;

&lt;span style="color:blue;"&gt;namespace &lt;/span&gt;LargeDBAppSample.Model
{
    &lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;GoodVirtualizedDataModel &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt;
    {
        &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DictionaryDatabaseContext &lt;/span&gt;dc = ((&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;)&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;.Current).DbDC;
        &lt;span style="color:blue;"&gt;int&lt;/span&gt;? cachedCount = &lt;span style="color:blue;"&gt;null&lt;/span&gt;;
        &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;gt; inMemoryLookup;
        &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;, &lt;span style="color:blue;"&gt;int&lt;/span&gt;&amp;gt; cachedPositions = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;,&lt;span style="color:blue;"&gt;int&lt;/span&gt;&amp;gt;();

        &lt;span style="color:blue;"&gt;public event &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;EventHandler &lt;/span&gt;InitializeCompleted;

        &lt;span style="color:blue;"&gt;public void &lt;/span&gt;BeginInitialize()
        {
            &lt;span style="color:#2b91af;"&gt;BackgroundWorker &lt;/span&gt;worker = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;BackgroundWorker&lt;/span&gt;();
            worker.DoWork += (s, e) =&amp;gt;
            {
                inMemoryLookup = (&lt;span style="color:blue;"&gt;from &lt;/span&gt;w &lt;span style="color:blue;"&gt;in &lt;/span&gt;dc.Words
                                  &lt;span style="color:blue;"&gt;orderby &lt;/span&gt;w.WordTxt
                                  &lt;span style="color:blue;"&gt;select &lt;/span&gt;w.WordTxt).ToList&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;gt;();

            };
            worker.RunWorkerCompleted += (s, e) =&amp;gt;
            {
                &lt;span style="color:blue;"&gt;if &lt;/span&gt;(InitializeCompleted != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)
                {
                    InitializeCompleted(&lt;span style="color:blue;"&gt;this&lt;/span&gt;, &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;EventArgs&lt;/span&gt;());
                }
            };
            worker.RunWorkerAsync();
        }

        &lt;span style="color:blue;"&gt;public int &lt;/span&gt;Count
        {
            &lt;span style="color:blue;"&gt;get &lt;/span&gt;{
                &lt;span style="color:blue;"&gt;if &lt;/span&gt;(!cachedCount.HasValue)
                {
                    &lt;span style="color:blue;"&gt;var &lt;/span&gt;wordcount = dc.Words.Count();
                    cachedCount = wordcount;
                }
                &lt;span style="color:blue;"&gt;return &lt;/span&gt;cachedCount.Value; 
            }
        }

        &lt;span style="color:green;"&gt;// Prepare a compiled query for optimum performance
        &lt;/span&gt;&lt;span style="color:blue;"&gt;public static &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;DictionaryDatabaseContext&lt;/span&gt;, &lt;span style="color:blue;"&gt;string&lt;/span&gt;, &lt;span style="color:#2b91af;"&gt;IQueryable&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt;&amp;gt; SelectedByIndexWordResult =
            System.Data.Linq.&lt;span style="color:#2b91af;"&gt;CompiledQuery&lt;/span&gt;.Compile(
            (&lt;span style="color:#2b91af;"&gt;DictionaryDatabaseContext &lt;/span&gt;dc, &lt;span style="color:blue;"&gt;string &lt;/span&gt;theWord) =&amp;gt;
                 &lt;span style="color:blue;"&gt;from &lt;/span&gt;w &lt;span style="color:blue;"&gt;in &lt;/span&gt;dc.Words
                 &lt;span style="color:blue;"&gt;where &lt;/span&gt;w.WordTxt == theWord
                 &lt;span style="color:blue;"&gt;select &lt;/span&gt;w
                 );

        &lt;span style="color:#2b91af;"&gt;Word IList&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt;.&lt;span style="color:blue;"&gt;this&lt;/span&gt;[&lt;span style="color:blue;"&gt;int &lt;/span&gt;index]
        {
            &lt;span style="color:blue;"&gt;get
            &lt;/span&gt;{
                &lt;span style="color:green;"&gt;//var word = from w in dc.Words
                //           where w.WordTxt == inMemoryLookup[index]
                //           select w;
                //return word.First&amp;lt;Word&amp;gt;();

                &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Stopwatch &lt;/span&gt;sw = &lt;span style="color:#2b91af;"&gt;Stopwatch&lt;/span&gt;.StartNew();
                &lt;span style="color:blue;"&gt;var &lt;/span&gt;word = SelectedByIndexWordResult(dc, inMemoryLookup[index]).First&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt;();
                &lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Fetched {0} in {1}ms&amp;quot;&lt;/span&gt;, &lt;span style="color:blue;"&gt;new object&lt;/span&gt;[] { index, sw.ElapsedMilliseconds });

                &lt;span style="color:blue;"&gt;return &lt;/span&gt;word;
            }
            &lt;span style="color:blue;"&gt;set
            &lt;/span&gt;{
                &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
            }
        }

        &lt;span style="color:blue;"&gt;public int &lt;/span&gt;IndexOf(&lt;span style="color:#2b91af;"&gt;Word &lt;/span&gt;item)
        {
            &lt;span style="color:#2b91af;"&gt;Stopwatch &lt;/span&gt;sw = &lt;span style="color:#2b91af;"&gt;Stopwatch&lt;/span&gt;.StartNew();
            &lt;span style="color:blue;"&gt;int &lt;/span&gt;position;

            &lt;span style="color:blue;"&gt;if &lt;/span&gt;(cachedPositions.ContainsKey(item.WordTxt))
            {
                position = cachedPositions[item.WordTxt];
            }
            &lt;span style="color:blue;"&gt;else
            &lt;/span&gt;{
                &lt;span style="color:blue;"&gt;var &lt;/span&gt;matches = inMemoryLookup
                    .Select((matchItem, index) =&amp;gt; &lt;span style="color:blue;"&gt;new &lt;/span&gt;{ theWord = matchItem, Position = index })
                                .Where(x =&amp;gt; x.theWord == item.WordTxt);

                position = matches.First().Position;

                cachedPositions[item.WordTxt] = position;
            }

            &lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Found position of {0} in {1}ms&amp;quot;&lt;/span&gt;, &lt;span style="color:blue;"&gt;new object&lt;/span&gt;[] { item.WordTxt, sw.ElapsedMilliseconds });

            &lt;span style="color:blue;"&gt;return &lt;/span&gt;position;
        }

        &lt;span style="color:blue;"&gt;#region &lt;/span&gt;NotRequired

        ...&lt;/pre&gt;&lt;pre class="code"&gt;        &lt;span style="color:blue;"&gt;#endregion
    &lt;/span&gt;}
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Using this in-memory lookup table, the results are impressive:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/L2S_2D00_Good_2D00_InMemory_5F00_6E84D153.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="L2S Good InMemory" border="0" alt="L2S Good InMemory" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/L2S_2D00_Good_2D00_InMemory_5F00_thumb_5F00_7E904DB2.png" width="697" height="526" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Of course, everything comes with a price. Using this in memory lookup, the building of the in-memory lookup takes 10-15 seconds on a device so you’ll have to show some ‘Please wait’ UI (I use a progress bar) or do it on a background thread while your user is still in the opening screens of your app. The lookup table also takes quite a lot of memory – up to 54MB with this sample set, which is not so bad, but in some earlier tests I did with 500000 items, my in-memory lookup was causing me to exceed the 90MB memory threshold. On the plus side, because the in-memory lookup is well – in memory – it’s easily updated if your app allows items to be added, edited or deleted from the main table.&lt;/p&gt;
&lt;h3&gt;Option 3: Data Virtualization – Best Implementation&lt;/h3&gt;
&lt;p&gt;So what do you do if you don’t want to have your users wait while you build the in-memory lookup index? Or you can’t afford the memory that the lookup table requires?&lt;/p&gt;
&lt;p&gt;Well, one solution is to let the database do the work for you, and this is what the final option demonstrates. Remember that third column, Sequence, that I said I would come back to? That is performing the same role as an in-memory lookup but instead it’s stored in the data base as well. I wrote a desktop utility program that prepared this database by fetching all the records using the primary key – in other words giving me the Words in alphabetical order – and then sets the Sequence field of each to its position in the collection. I then created a secondary key on the Sequence field (again before including the database in this project), so now I have a fast lookup of words both by WordTxt (the primary key) and by index (the secondary key).&lt;/p&gt;
&lt;p&gt;Using this, the final version of my virtualized data model looks like this:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;using &lt;/span&gt;System;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Linq;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Collections;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Collections.Generic;
&lt;span style="color:blue;"&gt;using &lt;/span&gt;System.Diagnostics;

&lt;span style="color:blue;"&gt;namespace &lt;/span&gt;LargeDBAppSample.Model
{
    &lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;BestVirtualizedDataModel &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt;
    {
        &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DictionaryDatabaseContext &lt;/span&gt;dc = ((&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;)&lt;span style="color:#2b91af;"&gt;App&lt;/span&gt;.Current).DbDC;
        &lt;span style="color:blue;"&gt;int&lt;/span&gt;? cachedCount = &lt;span style="color:blue;"&gt;null&lt;/span&gt;;
        &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;, &lt;span style="color:blue;"&gt;int&lt;/span&gt;&amp;gt; cachedPositions = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;,&lt;span style="color:blue;"&gt;int&lt;/span&gt;&amp;gt;();

        &lt;span style="color:blue;"&gt;public int &lt;/span&gt;Count
        {
            &lt;span style="color:blue;"&gt;get &lt;/span&gt;{
                &lt;span style="color:blue;"&gt;if &lt;/span&gt;(!cachedCount.HasValue)
                {
                    &lt;span style="color:blue;"&gt;var &lt;/span&gt;wordcount = dc.Words.Count();
                    cachedCount = wordcount;
                }
                &lt;span style="color:blue;"&gt;return &lt;/span&gt;cachedCount.Value; 
            }
        }

        &lt;span style="color:green;"&gt;// Prepare a compiled query for optimum performance
        &lt;/span&gt;&lt;span style="color:blue;"&gt;public static &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;DictionaryDatabaseContext&lt;/span&gt;, &lt;span style="color:blue;"&gt;int&lt;/span&gt;, &lt;span style="color:#2b91af;"&gt;IQueryable&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt;&amp;gt; SelectedBySecondaryIndexWordResult =
            System.Data.Linq.&lt;span style="color:#2b91af;"&gt;CompiledQuery&lt;/span&gt;.Compile(
            (&lt;span style="color:#2b91af;"&gt;DictionaryDatabaseContext &lt;/span&gt;dc, &lt;span style="color:blue;"&gt;int &lt;/span&gt;theIndex) =&amp;gt;
                 &lt;span style="color:blue;"&gt;from &lt;/span&gt;w &lt;span style="color:blue;"&gt;in &lt;/span&gt;dc.Words
                           &lt;span style="color:blue;"&gt;where &lt;/span&gt;w.Sequence == theIndex
                           &lt;span style="color:blue;"&gt;select &lt;/span&gt;w
                 );

        &lt;span style="color:#2b91af;"&gt;Word IList&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt;.&lt;span style="color:blue;"&gt;this&lt;/span&gt;[&lt;span style="color:blue;"&gt;int &lt;/span&gt;index]
        {
            &lt;span style="color:blue;"&gt;get
            &lt;/span&gt;{
                &lt;span style="color:#2b91af;"&gt;Stopwatch &lt;/span&gt;sw = &lt;span style="color:#2b91af;"&gt;Stopwatch&lt;/span&gt;.StartNew();

                &lt;span style="color:green;"&gt;//var word = from w in dc.Words
                //           where w.Sequence == index
                //           select w;
                //return word.First&amp;lt;Word&amp;gt;();

                &lt;/span&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;word = SelectedBySecondaryIndexWordResult(dc, index).First&amp;lt;&lt;span style="color:#2b91af;"&gt;Word&lt;/span&gt;&amp;gt;();
                &lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Fetched {0} in {1}ms&amp;quot;&lt;/span&gt;, &lt;span style="color:blue;"&gt;new object&lt;/span&gt;[] { index, sw.ElapsedMilliseconds });

                &lt;span style="color:blue;"&gt;return &lt;/span&gt;word;
            }
            &lt;span style="color:blue;"&gt;set
            &lt;/span&gt;{
                &lt;span style="color:blue;"&gt;throw new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;NotImplementedException&lt;/span&gt;();
            }
        }

        &lt;span style="color:blue;"&gt;public int &lt;/span&gt;IndexOf(&lt;span style="color:#2b91af;"&gt;Word &lt;/span&gt;item)
        {
            &lt;span style="color:#2b91af;"&gt;Stopwatch &lt;/span&gt;sw = &lt;span style="color:#2b91af;"&gt;Stopwatch&lt;/span&gt;.StartNew();
            &lt;span style="color:blue;"&gt;int &lt;/span&gt;position;

            &lt;span style="color:blue;"&gt;if &lt;/span&gt;(cachedPositions.ContainsKey(item.WordTxt))
            {
                position = cachedPositions[item.WordTxt];
            }
            &lt;span style="color:blue;"&gt;else
            &lt;/span&gt;{
                position = (&lt;span style="color:blue;"&gt;from &lt;/span&gt;w &lt;span style="color:blue;"&gt;in &lt;/span&gt;dc.Words
                           &lt;span style="color:blue;"&gt;where &lt;/span&gt;w.WordTxt == item.WordTxt
                           &lt;span style="color:blue;"&gt;select &lt;/span&gt;w.Sequence).First();

                cachedPositions[item.WordTxt] = position;
            }

            &lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Found position of {0} in {1}ms&amp;quot;&lt;/span&gt;, &lt;span style="color:blue;"&gt;new object&lt;/span&gt;[] { item.WordTxt, sw.ElapsedMilliseconds });

            &lt;span style="color:blue;"&gt;return &lt;/span&gt;position;
        }

        &lt;span style="color:blue;"&gt;#region &lt;/span&gt;NotRequired

        ...&lt;/pre&gt;&lt;pre class="code"&gt;        &lt;span style="color:blue;"&gt;#endregion
    &lt;/span&gt;}
}
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The results speak for themselves:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/L2S_2D00_Best_5F00_26CF5A3A.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="L2S Best" border="0" alt="L2S Best" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/L2S_2D00_Best_5F00_thumb_5F00_4AF3F322.png" width="594" height="442" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Memory usage here is around 23MB.&lt;/p&gt;
&lt;p&gt;So when not to use this option? Well, this only really works with read-only collections where you can get the Sequence numbers correct in the table before transferring to the device. It won’t work if you start inserting or removing records or changing the ordering – not without having to do massive data updates that would negate the benefit of the approach.&lt;/p&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;These examples have shown how to bind a very large collection of records from a local database table to a ListBox. This is rarely a great idea from a user experience point of view, unless you implement some kind of search as I have done in these examples. [An aside: my original intention had been to show a sample using the LongListSelector from the Silverlight Toolkit, configured as a JumpList, but that control does not support data virtualization, despite claims in a few blogs from the team to the contrary &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-thinkingsmile" alt="Thinking smile" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/wlEmoticon_2D00_thinkingsmile_5F00_27479EFD.png" /&gt;.] Nonetheless, a virtualized data source can be used in other situations where you want to avoid materializing all the records from a large table into memory.&lt;/p&gt;
&lt;p&gt;So if you are going to implement a virtualized data source, beware of the .Skip(n).Take(n1) syntax recommended by the MSDN docs – that does not work with large collections as it makes the database engine struggle as you get down towards the bottom of the list.&lt;/p&gt;
&lt;p&gt;Instead, implement your own way of efficiently determining the position of an item in the list, either by an in-memory lookup collection, or if your data is read-only by embedding positional information into a column in the database table and configuring it as a secondary index.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://skydrive.live.com/redir.aspx?cid=b36de4dd5a9179a1&amp;amp;resid=B36DE4DD5A9179A1!1334&amp;amp;parid=B36DE4DD5A9179A1!1333"&gt;Download the sample project&lt;/a&gt; (around 50MB)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h5&gt;Footnote:&lt;/h5&gt;
&lt;p&gt;I built this sample database using some excellent tools that deserve calling out. Firstly, I created a ‘big SQL’ database in SQL Express and designed my Word table. I then generated the random data using Red Gate’s excellent &lt;a href="http://www.red-gate.com/products/sql-development/sql-data-generator/"&gt;SQL Data Generator&lt;/a&gt;, part of their SQL Toolbelt product set. They have a 14 day free trial, which was just long enough while I was working on this post!&lt;/p&gt;
&lt;p&gt;I then scripted all the data and schema suitable for loading into a SQL Server Compact Edition 3.5 database using the free SQL export and script utility called Export2SQLCE, available &lt;a href="http://exportsqlce.codeplex.com/"&gt;here on Codeplex&lt;/a&gt;. Thanks Erik for these amazing (and free!) tools. Then it was back to SQL Server Management Studio to create an empty SQL Server Compact Edition 3.5 database and to execute all the scripts that Export2SQLCE had created for me. After this I had a database I could use on Windows Phone. I ran a small console app to set the sequence number in the table.&lt;/p&gt;
&lt;p&gt;Last part of the jigsaw was to generate the DataContext. I could have used SQLMetal utility for that, but I prefer to use another of Erik’s free tools, this time the &lt;a href="http://sqlcetoolbox.codeplex.com/"&gt;SQL Server Compact Toolbox&lt;/a&gt; which allows you to create a data context (amongst many other things).&lt;/p&gt;
&lt;p&gt;Thanks guys for these tools!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=423" width="1" height="1"&gt;</description><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Windows+Phone+7/default.aspx">Windows Phone 7</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/wp7dev/default.aspx">wp7dev</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/SQL+Server+Compact+Edition/default.aspx">SQL Server Compact Edition</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Linq+to+Sql/default.aspx">Linq to Sql</category></item><item><title>Mango Jump Start Videos–Just Released!</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2011/09/08/mango-jump-start-videos-just-released.aspx</link><pubDate>Thu, 08 Sep 2011 08:48:05 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:401</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;strong&gt;Microsoft have&lt;/strong&gt; &lt;b&gt;announced availability of the HD-quality video recordings – FREE – on &lt;a href="http://wpdev.ms/wpmgojs"&gt;Channel 9&lt;/a&gt;! &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;· The 14-hour course covers all aspects of Windows Phone development Visual Studio 2010, Silverlight, Expression, data storage, networks, user interface, XNA and the Marketplace.&lt;/p&gt;  &lt;p&gt;· “Team-teaching” approach led by MVPs Rob Miles and Andy Wigley&lt;/p&gt;  &lt;p&gt;· Every module is an engaging discussion, packed with best practices and real-world demonstrations&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Home page for the entire course on Channel 9: “&lt;a href="http://wpdev.ms/wpmgojs"&gt;Building Applications for Windows Phone Mango Jump Start&lt;/a&gt;”&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;· Links directly to specific modules:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;o Mango Jump Start (01): &lt;a href="http://channel9.msdn.com/posts/Mango-Jump-Start-01-Building-Windows-Phone-Apps-with-Visual-Studio-2010"&gt;Building Windows Phone Apps with Visual Studio 2010&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;o Mango Jump Start (02): &lt;a href="http://channel9.msdn.com/posts/Mango-Jump-Start-02-Silverlight-on-Windows-PhoneIntroduction"&gt;Silverlight on Windows Phone—Introduction&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;o Mango Jump Start (03): &lt;a href="http://channel9.msdn.com/posts/Mango-Jump-Start-03-Silverlight-on-Windows-PhoneAdvanced"&gt;Silverlight on Windows Phone—Advanced&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;o Mango Jump Start (04): &lt;a href="http://channel9.msdn.com/posts/Mango-Jump-Start-04-Using-Expression-Blend-to-Build-Windows-Phone-Interfaces"&gt;Using Expression to Build Windows Phone Interfaces&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;o Mango Jump Start (05): &lt;a href="http://channel9.msdn.com/posts/Mango-Jump-Start-05-Windows-Phone-Fast-Application-Switching"&gt;Windows Phone Fast Application Switching&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;o Mango Jump Start (06): &lt;a href="http://channel9.msdn.com/posts/Mango-Jump-Start-06-Windows-Phone-Multi-tasking--Background-Tasks"&gt;Windows Phone Multi-tasking &amp;amp; Background Tasks&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;o Mango Jump Start (07): &lt;a href="http://channel9.msdn.com/posts/Mango-Jump-Start-07-Using-Windows-Phone-Resources-Bing-Maps-Camera-etc"&gt;Using Windows Phone Resources (Bing Maps, Camera, etc.)&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;o Mango Jump Start (08a): &lt;a href="http://channel9.msdn.com/posts/Mango-Jump-Start-08a-Application-Data-Storage-on-Windows-Phone--Part-1"&gt;Application Data Storage on Windows Phone | Part 1&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;o Mango Jump Start (08b): &lt;a href="http://channel9.msdn.com/posts/Mango-Jump-Start-08b-Application-Data-Storage-on-Windows-Phone-Part-2"&gt;Application Data Storage on Windows Phone | Part 2&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;o Mango Jump Start (09): &lt;a href="http://channel9.msdn.com/posts/Mango-Jump-Start-09-Using-Networks-with-Windows-Phone"&gt;Using Networks with Windows Phone&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;o Mango Jump Start (10): &lt;a href="http://channel9.msdn.com/posts/Mango-Jump-Start-10-Tiles--Notifications-on-Windows-Phone"&gt;Tiles &amp;amp; Notifications on Windows Phone&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;o Mango Jump Start (11a): &lt;a href="http://channel9.msdn.com/posts/Mango-Jump-Start-11a-XNA-for-Windows-Phone--Part-1"&gt;XNA for Windows Phone | Part 1&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;o Mango Jump Start (11b): &lt;a href="http://channel9.msdn.com/posts/Mango-Jump-Start-11b-XNA-for-Windows-Phone--Part-2"&gt;XNA for Windows Phone | Part 2&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;o Mango Jump Start (12): &lt;a href="http://channel9.msdn.com/posts/Mango-Jump-Start-12-Selling-a-Windows-Phone-Application"&gt;Selling a Windows Phone Application&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;· Links to &lt;a href="http://borntolearn.mslearn.net/wpmango/m/mediagallery/default.aspx"&gt;course materials&lt;/a&gt; on Born to Learn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=401" width="1" height="1"&gt;</description><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Windows+Phone+7/default.aspx">Windows Phone 7</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/wp7dev/default.aspx">wp7dev</category></item><item><title>Want a FREE Windows Phone??</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2011/03/29/want-a-free-windows-phone.aspx</link><pubDate>Tue, 29 Mar 2011 13:41:00 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:355</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;APPA Mundi has a large number of Windows Phone 7 Developer Phones to give away to UK developers&amp;nbsp;(Thanks to Microsoft)! All you have to do is come to one of our workshops (see below) and create a unique and high quality Windows Phone 7 app and get it published on Marketplace. &lt;/p&gt;
&lt;p&gt;Who decides if your app is &amp;lsquo;unique and high quality&amp;rsquo;? We do!! We&amp;rsquo;ll take a look at it and if we like what we see, we&amp;rsquo;ll give you a code you can use to purchase one of the new Windows Phone Developer phones at ZERO cost! And if we think it&amp;rsquo;s nearly there, we&amp;rsquo;ll give you some feedback and you can update your app &amp;ndash; then we&amp;rsquo;ll give you a code.&lt;/p&gt;
&lt;p&gt;The best way of ensuring your app is high quality and catches our attention is to come to one of our upcoming Windows Phone 7 Workshops. These are FREE, and are running on each of the next three Saturdays, 9:00 &amp;ndash; 21:00, at the following locations (follow the links to register):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.clicktoattend.com/invitation.aspx?code=154634"&gt;&lt;strong&gt;Hallam Conference Centre, London&lt;/strong&gt;&lt;/a&gt; Saturday April 2nd &lt;br /&gt;44 Hallam Street, London, W1W 6JJ &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://www.clicktoattend.com/invitation.aspx?code=154635"&gt;Manchester Conference Centre&lt;/a&gt; &lt;/strong&gt;Saturday April &lt;br /&gt;9th Sackville Street, Manchester, M1 3BB &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://www.clicktoattend.com/invitation.aspx?code=154636"&gt;London, LBi Atlantis Building&lt;/a&gt;&lt;/strong&gt; Saturday April 16th &lt;br /&gt;LBi Atlantis Building, Truman Brewery, 146 Brick Lane, London , E1 6RU &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The first workshop was last week, was a *load* of fun and everyone who attended agreed it was a really worthwhile use of their time. We&amp;rsquo;ve got lots of prizes to give away at each workshop such as software, a Windows Phone 7 device for the best app on the day, and a raffle for an XBox+Kinect, amongst other things. We also will have a &amp;lsquo;performance area&amp;rsquo; where we will run little seminars aimed at inexperienced developers on topics such as databinding, launchers and choosers, tombstoning, page transition animations etc. For full details, see &lt;a href="http://appamundi.com/wp7workshops/" title="http://appamundi.com/wp7workshops/"&gt;http://appamundi.com/wp7workshops/&lt;/a&gt; .&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=355" width="1" height="1"&gt;</description><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Windows+Phone+7/default.aspx">Windows Phone 7</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/wp7dev/default.aspx">wp7dev</category></item><item><title>Calling West Midlands WP7 Enthusiasts!</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2011/03/14/calling-west-midlands-wp7-enthusiasts.aspx</link><pubDate>Mon, 14 Mar 2011 14:13:56 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:346</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;APPA Mundi and Microsoft are holding a &lt;strong&gt;WP7 Workshop&lt;/strong&gt; at The Studio, 7 Cannon Street, Birmingham, B2 5EP on &lt;strong&gt;Saturday 27&lt;sup&gt;th&lt;/sup&gt; March 2011&lt;/strong&gt;. Start at 9:00 running through to 21:00. Lunch and beverages provided!&lt;/p&gt;  &lt;p&gt;If you are creating apps for Windows Phone 7, as a professional, independent or student developer please join us at this free Windows Phone 7 workshop, which is all about APPs!! The goal is to get as many apps ready for Marketplace submission as possible, to give you the opportunity to get one-on-one assistance from MVPs and Microsoft evangelists to overcome issues that are blocking you, to get help with the Marketplace app submission process and to have some fun along the way. &lt;/p&gt;  &lt;p&gt;We’ll be providing prizes at each event: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Windows Phone 7 devices&lt;/li&gt;    &lt;li&gt;An Xbox and Kinect system &lt;/li&gt;    &lt;li&gt;Software licenses for .Net Reflector from RedGate&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So come along if:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;You’ve got a great idea for an app and need help getting started&lt;/li&gt;    &lt;li&gt;You’re building an app but need help on implementing some features&lt;/li&gt;    &lt;li&gt;You have an app that’s nearly ready and need advice on how to get it through the Marketplace submission process&lt;/li&gt;    &lt;li&gt;You want to learn from, or assist, other WP7 devs &lt;/li&gt;    &lt;li&gt;You want to contribute to the creation of open source libraries, demo/starter apps or components&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Sign up at &lt;a href="http://www.developerdeveloperdeveloper.com"&gt;http://www.developerdeveloperdeveloper.com&lt;/a&gt; – book early as places are limited to the first 50 people to register!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=346" width="1" height="1"&gt;</description><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Windows+Phone+7/default.aspx">Windows Phone 7</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/wp7dev/default.aspx">wp7dev</category></item><item><title>Tech.Days Online Conference – Create.Design.Deliver | Windows Phone 7</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2011/02/25/tech-days-online-conference-create-design-deliver-windows-phone-7.aspx</link><pubDate>Fri, 25 Feb 2011 11:39:33 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:340</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;On March 24th, I am one of the speakers at a Tech.Days Online Conference on Windows Phone 7. The event is presented by the MSDN UK Team, assisted by a few outside speakers such as myself and Laurent Guignion. It starts at 15:00 hrs and runs through to 20:30 hrs. If you can’t make it online, the sessions will be recorded and made available a few days later.&lt;/p&gt;  &lt;p&gt;Here’s the agenda: I am presenting on programming Windows Phone Notification Services. &lt;/p&gt; &lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/image_5F00_3BDE64F6.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/image_5F00_thumb_5F00_6D7936B1.png" width="508" height="326" /&gt;&lt;/a&gt;   &lt;p&gt;To find out more details, and to register for the event see &lt;a href="http://blogs.msdn.com/b/ukmsdn/archive/2011/02/24/wanna-get-creative-on-24-march.aspx?WT.mc_id=eml-n-gb-wp7--Q3"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=340" width="1" height="1"&gt;</description><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Windows+Phone+7/default.aspx">Windows Phone 7</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/wp7dev/default.aspx">wp7dev</category></item><item><title>Windows Phone 7 at the App Developers Conference at Mobile World Congress</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2011/01/29/windows-phone-7-at-the-app-developers-conference-at-mobile-world-congress.aspx</link><pubDate>Sat, 29 Jan 2011 14:07:52 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:324</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;If you are going to Mobile World Congress in Barcelona, there is a great Windows Phone 7 developer event happening:&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Windows Phone Wednesday 16th February, the App Developers Conference at Mobile World Congress&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Calling all developers!!!!   &lt;br /&gt;If you are interested in learning more about developing apps for Windows Phone 7 then do we have the event for you...    &lt;br /&gt;“The Why and How’s of Windows Phone 7”    &lt;br /&gt;Presented by Microsoft&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;Join us on a whirlwind tour around the landscape of the    &lt;br /&gt;Windows Phone platform. The daylong session will examine    &lt;br /&gt;all aspects of development on the phone, including building    &lt;br /&gt;apps and games, marketplace monetization, tips and trick for     &lt;br /&gt;certification and an open panel discussion where you can get    &lt;br /&gt;answers to your burning questions.    &lt;br /&gt;Get in on the ground floor with us and see what makes    &lt;br /&gt;us different!”&lt;/p&gt;  &lt;p&gt;Day long sessions includes:   &lt;table cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td&gt;           &lt;p&gt;Time&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Session Title&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Speaker&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td&gt;           &lt;p&gt;9:30-10:00&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;State of the Union&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Brandon Watson&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td&gt;           &lt;p&gt;10:00-10:30&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Platform Overview&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Larry Lieberman&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td&gt;           &lt;p&gt;10:30-11:30&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;UX/Metro Design Review&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Bryan Agnetta&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td&gt;           &lt;p&gt;11:30-11:45&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Break&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;&amp;nbsp;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td&gt;           &lt;p&gt;11:45-12:45&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Mobile Web Platform Futures&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Joe Marini&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td&gt;           &lt;p&gt;12:45-1:45&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Lunch&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;&amp;nbsp;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td&gt;           &lt;p&gt;1:45-2:45&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Panel discussion&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;&amp;nbsp;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td&gt;           &lt;p&gt;2:45-3:00&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Break&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;&amp;nbsp;&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td&gt;           &lt;p&gt;3:00-4:00&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Business of your App&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Todd Biggs&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td&gt;           &lt;p&gt;4:00-5:00&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Silverlight/XNA overview&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;Rob Cameron&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;The conference pass gets you into the ADC as well as into the Expo Hall at Mobile World Congress.    &lt;br /&gt;If you are interested please send an email to &lt;a href="mailto:creators@microsoft.com"&gt;creators@microsoft.com&lt;/a&gt; with the following details:    &lt;br /&gt;First and last name    &lt;br /&gt;email address for the invite     &lt;br /&gt;Company name&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;We are limited to 200 passes so sign up early     &lt;br /&gt;We look forward to seeing you there!!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=324" width="1" height="1"&gt;</description><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Windows+Phone+7/default.aspx">Windows Phone 7</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/wp7dev/default.aspx">wp7dev</category></item><item><title>Best of breed Page rotation animations</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2010/11/24/best-of-breed-page-rotation-animations.aspx</link><pubDate>Wed, 24 Nov 2010 11:37:00 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:294</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>6</slash:comments><description>&lt;p&gt;In &lt;a href="http://mobileworld.appamundi.com/blogs/andywigley/archive/2010/11/23/windows-phone-7-page-orientation-change-animations.aspx"&gt;my previous post&lt;/a&gt;, I showed how to use the page rotate transitions offered in&amp;nbsp; the &lt;a href="http://silverlight.codeplex.com/releases/view/55034"&gt;Silverlight for Windows Phone Toolkit November 2010&lt;/a&gt;. Those animations are pretty easy to use, but require you to write some code to decide which direction to animate &amp;ndash; and we don&amp;rsquo;t like to write unnecessary code.&lt;/p&gt;
&lt;p&gt;Also, the resulting animations are OK, but not as good as the ones created by David Anson of Microsoft which he described in a series of blog posts culminating in the ultimate implementation, the &lt;span style="font-family:Courier New;"&gt;HybridOrientationChangesFrame&lt;/span&gt; which he describes in &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/28/this-one-s-for-you-gregor-mendel-code-to-animate-and-fade-windows-phone-orientation-changes-now-supports-a-new-mode-hybrid.aspx"&gt;this blog post&lt;/a&gt; in September 2010. Davids&amp;rsquo; animations are great, are designed to execute solely on the GPU to give great performance, and come in subtly different flavours, AnimateOrientationChanges, FadeOrientationChanges and HybridorientationChanges as he described in his post. They also *just work* without you having to write any code in an OrientationChanged event handler.&lt;/p&gt;
&lt;p&gt;The Hybrid flavour combines the best bits of AnimateOrientationChanges and FadeOrientationChanges and &amp;ndash; as David describes in his post &amp;ndash; &amp;ldquo;&amp;hellip; animates the rotation between the &amp;quot;before&amp;quot; and &amp;quot;after&amp;quot; states - but fades between them instead of morphing from one shape into the other. The idea is to get some of the same &amp;quot;&lt;em&gt;Ooh, the application is turning!&lt;/em&gt;&amp;quot; visual appeal of &lt;code&gt;AnimateOrientationChangesFrame&lt;/code&gt; &lt;strong&gt;without&lt;/strong&gt; the undesirable performance implications for complex layouts. Because the &amp;quot;before&amp;quot; and &amp;quot;after&amp;quot; states don&amp;#39;t change size in the proposed scenario, the entire animation can be done on the composition (render) thread! This same visual effect is implemented by some of the core Windows Phone 7 applications - so now it&amp;#39;s easy to match that effect in your &lt;strong&gt;own&lt;/strong&gt; applications with &lt;code&gt;HybridOrientationChangesFrame&lt;/code&gt;! &amp;ldquo;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/orientationchanges_5F00_330985AD.png"&gt;&lt;img height="356" width="644" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/orientationchanges_5F00_thumb_5F00_67E6651D.png" alt="orientationchanges" border="0" title="orientationchanges" style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A small problem presents itself if you want to use David&amp;rsquo;s orientation animations as well as the Page transition animations (page turn animations) you get in the Silverlight Toolkit. David&amp;rsquo;s animations are implemented in a custom Frame, and so are the Toolkit page transitions but since source code is available for both, I thought it shouldn&amp;rsquo;t be too difficult to merge the two.&lt;/p&gt;
&lt;p&gt;In fact, I emailed david about it and he suggested that it might be as easy as changing the base class of his HybridorientationChangesFrame from PhoneApplicationFrame to the TransitionFrame included in the toolkit. I tested it out, and that&amp;rsquo;s all it took!&lt;/p&gt;
&lt;p&gt;To do this yourself, download David&amp;rsquo;s solution code from the link on &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/28/this-one-s-for-you-gregor-mendel-code-to-animate-and-fade-windows-phone-orientation-changes-now-supports-a-new-mode-hybrid.aspx"&gt;this blog post&lt;/a&gt;, unzip it and then open the solution in Visual Studio. Go to the DynamicOrientationChanges project and add a reference to Microsoft.Phone.Controls.Toolkit &amp;ndash; the Silverlight Toolkit assembly. Then change the base class in AnimateOrientationChangesFrame, FadeOrientationChangesFrame and HybridOrientationChangesFrame from PhoneApplicationFrame to TransitionFrame (the custom frame from the Toolkit).&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:#808080;"&gt;/// &amp;lt;summary&amp;gt;
/// &lt;/span&gt;&lt;span style="color:#008000;"&gt;PhoneApplicationFrame subclass that animates and fades between device orientation changes.
&lt;/span&gt;&lt;span style="color:#808080;"&gt;/// &amp;lt;/summary&amp;gt;
&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;HybridOrientationChangesFrame &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;&lt;strong&gt;TransitionFrame&lt;/strong&gt;
&lt;/span&gt;{
   ...&lt;/pre&gt;
&lt;p&gt;That&amp;rsquo;s it! Now you can use Davids&amp;rsquo; rotate animations as well as the Toolkit Page transitions as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Add a reference to the DynamicOrientationChanges.dll you just built from the sample code, or add one of the AnimateOrientationChangesFrame, FadeOrientationChangesFrame or HybridOrientationChangesFrame directly to your project.&lt;/li&gt;
&lt;li&gt;Add a reference to the Silverlight Toolkit for Windows Phone to your project:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/image_5F00_23764E11.png"&gt;&lt;img height="484" width="639" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/image_5F00_thumb_5F00_612335CD.png" alt="image" border="0" title="image" style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Edit the InitializePhoneApplication method in App.xaml.cs and set RootFrame to your preferred rotate transitions frame. Optionally set any properties to affect the rotate animation &amp;ndash; I prefer a duration of 0.6s:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="code"&gt;&lt;span style="color:#0000ff;"&gt;private void &lt;/span&gt;InitializePhoneApplication()
{
    &lt;span style="color:#0000ff;"&gt;if &lt;/span&gt;(phoneApplicationInitialized)
        &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt;;

    &lt;span style="color:#008000;"&gt;// Create the frame but don&amp;#39;t set it as RootVisual yet; this allows the splash
    // screen to remain active until the application is ready to render.&lt;br /&gt;    //RootFrame = new PhoneApplicationFrame(); // This is the standard Frame in a WP7 project&lt;/span&gt;&lt;span style="color:#008000;"&gt;
    //RootFrame = new TransitionFrame(); // This uses the custom Frame in the Silverlight Toolkit
    &lt;/span&gt;RootFrame = &lt;span style="color:#0000ff;"&gt;new &lt;/span&gt;Delay.&lt;span style="color:#2b91af;"&gt;HybridOrientationChangesFrame&lt;/span&gt;();  &lt;span style="color:#008000;"&gt;// Use the rotation-enhanced custom Frame that &lt;br /&gt;                                                            // derives from the Toolkit TransitionFrame
    &lt;/span&gt;((Delay.&lt;span style="color:#2b91af;"&gt;HybridOrientationChangesFrame&lt;/span&gt;)RootFrame).Duration = &lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt;.FromSeconds(0.6);

    ...&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Finally, implement any Page transitions you want to use by adding the required XAML to each page, as described briefly in &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/11/02/mo-controls-mo-controls-mo-controls-announcing-the-second-release-of-the-silverlight-for-windows-phone-toolkit.aspx"&gt;this post also by David Anson&lt;/a&gt; or in more detail by Will Faught &lt;a href="http://blogs.msdn.com/b/wfaught/archive/2010/11/15/transitions.aspx"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That&amp;rsquo;s It! Now you can enjoy the best screen rotate transformations and the Silverlight Toolkit page transitions together. &lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=294" width="1" height="1"&gt;</description><enclosure url="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.00.02.94/DynamicOrientationChanges-with-Toolkit.zip" length="79093" type="application/x-zip-compressed" /><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Windows+Phone+7/default.aspx">Windows Phone 7</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/wp7dev/default.aspx">wp7dev</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/_2300_wp7dev/default.aspx">#wp7dev</category></item><item><title>Windows Phone 7 Page Orientation Change Animations</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2010/11/23/windows-phone-7-page-orientation-change-animations.aspx</link><pubDate>Tue, 23 Nov 2010 15:23:00 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:291</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>4</slash:comments><description>&lt;p&gt;If you want your Windows Phone 7 Silverlight apps to look great and to integrate well with the phone look and feel, then you need to have good animations when moving from page to page, and if you&amp;rsquo;ve supported portrait and landscape orientations in your pages, when your user changes from portrait to landscape orientation and vice-versa. Of course, these kind of animations should be built into the standard project templates but currently they&amp;rsquo;re not &amp;ndash; although I&amp;rsquo;d expect that to be rectified in some future release of the developer tools.&lt;/p&gt;
&lt;p&gt;Fortunately, an easy remedy for this is available now. The &lt;a href="http://silverlight.codeplex.com/releases/view/55034"&gt;Silverlight for Windows Phone Toolkit November 2010&lt;/a&gt; has been released which contains lots of goodies, including lots of controls and something called the TransitionFrame which is a custom PhoneApplicationFrame that has been tweaked to add support for page and rotate transitions. David Anson blogged about all the great stuff in the toolkit &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/11/02/mo-controls-mo-controls-mo-controls-announcing-the-second-release-of-the-silverlight-for-windows-phone-toolkit.aspx"&gt;here&lt;/a&gt;.&amp;nbsp; Will Faught from the Silverlight Toolkit team &lt;a href="http://blogs.msdn.com/b/wfaught/archive/2010/11/15/transitions.aspx"&gt;blogged about the page transitions built into the Silverlight Toolkit bits&lt;/a&gt; so if you want to find out more about those, read his post.&lt;/p&gt;
&lt;p&gt;So, there&amp;rsquo;s been plenty of coverage of the page transitions, but not much has been said about the Orientation change transitions. You enable support for both portrait and landscape orientations by setting the SupportedOrientations attribute of your PhoneApplicationPage as follows:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:#0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;phone&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:&lt;/span&gt;&lt;span style="color:#a31515;"&gt;PhoneApplicationPage 
    &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;x&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Class&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;ToolkitRotateAnimations.MainPage&amp;quot;
    &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;hellip;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;    &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;SupportedOrientations&lt;/strong&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&lt;strong&gt;=&amp;quot;PortraitOrLandscape&amp;quot;&lt;/strong&gt; &lt;/span&gt;&lt;span style="color:#ff0000;"&gt;Orientation&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;=&amp;quot;Portrait&amp;quot;
    &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;That is enough for the page to re-orientate automatically when the user rotates the phone from portrait to landscape or vice-versa, but by default there&amp;rsquo;s no built-in animation so it just snaps to the new orientation, which is ugly.&lt;/p&gt;
&lt;p&gt;To add an animation when the display re-orientates, download and install the Silverlight for Windows Phone Toolkit November 2010 (or later) and then in your project, add a reference to the System.Windows.Controls.Toolkit assembly &amp;ndash; you&amp;rsquo;ll find that on the .NET tab.&lt;/p&gt;
&lt;p&gt;All you need to do, is to code an event handler for the OrientationChanged event of your Page object, and write code similar to the following:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:#0000ff;"&gt;public partial class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MainPage &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;PhoneApplicationPage
&lt;/span&gt;{
    &lt;span style="color:#2b91af;"&gt;PageOrientation &lt;/span&gt;lastOrientation;

    &lt;span style="color:#008000;"&gt;// Constructor
    &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;public &lt;/span&gt;MainPage()
    {
        InitializeComponent();

        &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.OrientationChanged += &lt;span style="color:#0000ff;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;EventHandler&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;OrientationChangedEventArgs&lt;/span&gt;&amp;gt;(MainPage_OrientationChanged);

        lastOrientation = &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt;.Orientation;
    }

    &lt;span style="color:#0000ff;"&gt;void &lt;/span&gt;MainPage_OrientationChanged(&lt;span style="color:#0000ff;"&gt;object &lt;/span&gt;sender, &lt;span style="color:#2b91af;"&gt;OrientationChangedEventArgs &lt;/span&gt;e)
    {
        &lt;span style="color:#2b91af;"&gt;PageOrientation &lt;/span&gt;newOrientation = e.Orientation;
        &lt;span style="color:#2b91af;"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;New orientation: &amp;quot; &lt;/span&gt;+ newOrientation.ToString());

        &lt;span style="color:#008000;"&gt;// Orientations are (clockwise) &amp;#39;PortraitUp&amp;#39;, &amp;#39;LandscapeRight&amp;#39;, &amp;#39;LandscapeLeft&amp;#39;

        &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;RotateTransition &lt;/span&gt;transitionElement = &lt;span style="color:#0000ff;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;RotateTransition&lt;/span&gt;();

        &lt;span style="color:#0000ff;"&gt;switch &lt;/span&gt;(newOrientation)
        {
            &lt;span style="color:#0000ff;"&gt;case &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;PageOrientation&lt;/span&gt;.Landscape:
            &lt;span style="color:#0000ff;"&gt;case &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;PageOrientation&lt;/span&gt;.LandscapeRight:
                &lt;span style="color:#008000;"&gt;// Come here from PortraitUp (i.e. clockwise) or LandscapeLeft?
                &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;if &lt;/span&gt;(lastOrientation == &lt;span style="color:#2b91af;"&gt;PageOrientation&lt;/span&gt;.PortraitUp)
                    transitionElement.Mode = &lt;span style="color:#2b91af;"&gt;RotateTransitionMode&lt;/span&gt;.In90Counterclockwise;
                &lt;span style="color:#0000ff;"&gt;else
                    &lt;/span&gt;transitionElement.Mode = &lt;span style="color:#2b91af;"&gt;RotateTransitionMode&lt;/span&gt;.In180Clockwise;
                &lt;span style="color:#0000ff;"&gt;break&lt;/span&gt;;
            &lt;span style="color:#0000ff;"&gt;case &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;PageOrientation&lt;/span&gt;.LandscapeLeft:
                &lt;span style="color:#008000;"&gt;// Come here from LandscapeRight or PortraitUp?
                &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;if &lt;/span&gt;(lastOrientation == &lt;span style="color:#2b91af;"&gt;PageOrientation&lt;/span&gt;.LandscapeRight)
                    transitionElement.Mode = &lt;span style="color:#2b91af;"&gt;RotateTransitionMode&lt;/span&gt;.In180Counterclockwise;
                &lt;span style="color:#0000ff;"&gt;else
                    &lt;/span&gt;transitionElement.Mode = &lt;span style="color:#2b91af;"&gt;RotateTransitionMode&lt;/span&gt;.In90Clockwise;
                &lt;span style="color:#0000ff;"&gt;break&lt;/span&gt;;
            &lt;span style="color:#0000ff;"&gt;case &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;PageOrientation&lt;/span&gt;.Portrait:
            &lt;span style="color:#0000ff;"&gt;case &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;PageOrientation&lt;/span&gt;.PortraitUp:
                &lt;span style="color:#008000;"&gt;// Come here from LandscapeLeft or LandscapeRight?
                &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;if &lt;/span&gt;(lastOrientation == &lt;span style="color:#2b91af;"&gt;PageOrientation&lt;/span&gt;.LandscapeLeft)
                    transitionElement.Mode = &lt;span style="color:#2b91af;"&gt;RotateTransitionMode&lt;/span&gt;.In90Counterclockwise;
                &lt;span style="color:#0000ff;"&gt;else
                    &lt;/span&gt;transitionElement.Mode = &lt;span style="color:#2b91af;"&gt;RotateTransitionMode&lt;/span&gt;.In90Clockwise;
                &lt;span style="color:#0000ff;"&gt;break&lt;/span&gt;;
            &lt;span style="color:#0000ff;"&gt;default&lt;/span&gt;:
                &lt;span style="color:#0000ff;"&gt;break&lt;/span&gt;;
        }

        &lt;span style="color:#008000;"&gt;// Execute the transition
        &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;PhoneApplicationPage &lt;/span&gt;phoneApplicationPage = (&lt;span style="color:#2b91af;"&gt;PhoneApplicationPage&lt;/span&gt;)(((&lt;span style="color:#2b91af;"&gt;PhoneApplicationFrame&lt;/span&gt;)&lt;span style="color:#2b91af;"&gt;Application&lt;/span&gt;.Current.RootVisual)).Content;
        &lt;span style="color:#2b91af;"&gt;ITransition &lt;/span&gt;transition = transitionElement.GetTransition(phoneApplicationPage);
        transition.Completed += &lt;span style="color:#0000ff;"&gt;delegate
        &lt;/span&gt;{
            transition.Stop();
        };
        transition.Begin();

        lastOrientation = newOrientation;
    }
}&lt;/pre&gt;
&lt;p&gt;After numerous attempts with OneNote, I managed to get a screen capture with it in mid-animation:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/image_5F00_1654E215.png"&gt;&lt;img height="335" width="644" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/image_5F00_thumb_5F00_7F65EACB.png" alt="image" border="0" title="image" style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This gives a pleasing enough effect, but in my opinion this takes too much code, and there are better rotate animations out there in the blogosphere. In &lt;a target="_self" href="http://mobileworld.appamundi.com/blogs/andywigley/archive/2010/11/24/best-of-breed-page-rotation-animations.aspx" title="Best of breed rotate animations"&gt;my next post&lt;/a&gt;, I&amp;rsquo;ll show you how to get even more pleasing rotate transformations.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=291" width="1" height="1"&gt;</description><enclosure url="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.00.02.91/ToolkitRotateAnimations.zip" length="33096" type="application/x-zip-compressed" /><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Windows+Phone+7/default.aspx">Windows Phone 7</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/_2300_wp7dev/default.aspx">#wp7dev</category></item><item><title>Perst Database for Windows Phone 7: Demo Updated to RTM</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2010/11/09/perst-database-for-windows-phone-7-demo-updated-to-rtm.aspx</link><pubDate>Tue, 09 Nov 2010 04:36:13 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:280</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;Get the source code for Perst database on Windows Phone 7 and demo app &lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.00.01.85/PerstDemo.zip" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I’ve been a bit slow in doing this, but thanks to a number of requests from interested people, I have updated the Perst demo so that it works with the final version of the Windows Phone 7 libraries and tools. Click the link at the bottom of this post to download all the source code – includes the Perst database and the demo app.&lt;/p&gt;  &lt;p&gt;The demo app is much expanded. Most importantly, it now fully supports tombstoning, which was a pretty significant omission from the previous version. &lt;/p&gt;  &lt;p&gt;The demo app displays a list of contact records on the main page, and when the user selects a record in the list, the app navigates to a new page to show the details of the contact. This page now uses a Pivot control, so not only do we see the contact, but a swipe to left or right now displays the Leads for that contact.The best way of supporting tombstoning with a page displaying the details view of a single record in the database, is to save the object ID that every record in a Perst database has (inherited from the Persistent base class) when the app is being tombstoned, like this:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;protected override void &lt;/span&gt;OnNavigatedFrom(System.Windows.Navigation.&lt;span style="color:#2b91af;"&gt;NavigationEventArgs &lt;/span&gt;e)
{
    &lt;span style="color:blue;"&gt;base&lt;/span&gt;.OnNavigatedFrom(e);

    &lt;span style="color:green;"&gt;// Save OID of the current record we are viewing/editing
    &lt;/span&gt;State[&lt;span style="color:#a31515;"&gt;&amp;quot;DataContextObjectID&amp;quot;&lt;/span&gt;] = ((&lt;span style="color:#2b91af;"&gt;Contact&lt;/span&gt;)&lt;span style="color:blue;"&gt;this&lt;/span&gt;.DataContext).Oid;
}&lt;/pre&gt;

&lt;p&gt;Then, when the app is being reactivated, we can do a simple database lookup to pull the required record out again:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;protected override void &lt;/span&gt;OnNavigatedTo(System.Windows.Navigation.&lt;span style="color:#2b91af;"&gt;NavigationEventArgs &lt;/span&gt;e)
{
    &lt;span style="color:blue;"&gt;base&lt;/span&gt;.OnNavigatedTo(e);

    &lt;span style="color:green;"&gt;// For tombstoning, save the oid of a particular record in the State object on OnNavigatedFrom
    // Restore it in OnNavigatedTo and use the Database.Select&amp;lt;T&amp;gt; method to extract the correct one from the database
    &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;(State.ContainsKey(&lt;span style="color:#a31515;"&gt;&amp;quot;DataContextObjectID&amp;quot;&lt;/span&gt;))
    {
        &lt;span style="color:blue;"&gt;int &lt;/span&gt;oid = (&lt;span style="color:blue;"&gt;int&lt;/span&gt;)State[&lt;span style="color:#a31515;"&gt;&amp;quot;DataContextObjectID&amp;quot;&lt;/span&gt;];
        &lt;span style="color:blue;"&gt;this&lt;/span&gt;.DataContext = Database.Select&amp;lt;&lt;span style="color:#2b91af;"&gt;Contact&lt;/span&gt;&amp;gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;oid = &amp;quot; &lt;/span&gt;+ oid.ToString()).FirstOrDefault();
        State.Remove(&lt;span style="color:#a31515;"&gt;&amp;quot;DataContextObjectID&amp;quot;&lt;/span&gt;);
    }

    &lt;span style="color:green;"&gt;// Have we come here by navigating from the MainPage after selecting a record in the main list?
    &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;(&lt;span style="color:blue;"&gt;this&lt;/span&gt;.NavigationContext.QueryString.ContainsKey(&lt;span style="color:#a31515;"&gt;&amp;quot;oid&amp;quot;&lt;/span&gt;))
    {
        &lt;span style="color:blue;"&gt;this&lt;/span&gt;.DataContext = Database.Select&amp;lt;&lt;span style="color:#2b91af;"&gt;Contact&lt;/span&gt;&amp;gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;oid = &amp;quot; &lt;/span&gt;+ &lt;span style="color:blue;"&gt;this&lt;/span&gt;.NavigationContext.QueryString[&lt;span style="color:#a31515;"&gt;&amp;quot;oid&amp;quot;&lt;/span&gt;]).FirstOrDefault();
    }
}&lt;/pre&gt;

&lt;p&gt;There are two ways for the details page to be activated: when the app is being reactivated after tombstoning and this page is the current page in the app, or when the user selects a record from the list on the main page. In the latter case, the demo app puts the Oid of the selected record into the query string. This is why the OnNavigatedTo method includes code to look for the Oid either from the State object (used to save context while tombstoning) or from the query string.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The previous version of the demo app included code to generate thousands of contacts. Each contact has a collection of Leads, and each lead has a collection of Activities. Lead and Activity objects were generated by the app before, but there was no UI to show them. Now there is:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/image_5F00_70BAB0F8.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/image_5F00_thumb_5F00_656176EE.png" width="262" height="484" /&gt;&lt;/a&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/image_5F00_49DC74EB.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/image_5F00_thumb_5F00_58C3A405.png" width="263" height="484" /&gt;&lt;/a&gt;&amp;#160;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/image_5F00_23D69EC8.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/image_5F00_thumb_5F00_4BB99E27.png" width="263" height="484" /&gt;&lt;/a&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/image_5F00_65412B54.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/image_5F00_thumb_5F00_74285A6E.png" width="263" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I haven’t included code to add, edit, delete Leads and Activities – but that is essentially the same kind of code that is included for performing those operations on a Contact. That’s left as an exercise for the interested reader &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/wlEmoticon_2D00_smile_5F00_58A3586B.png" /&gt;&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=280" width="1" height="1"&gt;</description><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Perst/default.aspx">Perst</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Windows+Phone+7/default.aspx">Windows Phone 7</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/wp7dev/default.aspx">wp7dev</category></item><item><title>Windows Phone 7 Jump Start–Reloaded!</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2010/11/02/windows-phone-7-jump-start-reloaded.aspx</link><pubDate>Tue, 02 Nov 2010 12:40:24 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:274</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;Some weeks ago, Rob Miles and I travelled over to Redmond to record some new videos for the Windows Phone 7 Jump Start series to coincide with the release of the final version of the developer tools. We also re-recorded some of the earlier sessions that covered topics that had changed between the beta and RTM. It was fun as always, and Rob managed to come up with some new awful jokes. Many thanks to Jeff, Sharon and Bob for making it happen.&lt;/p&gt;  &lt;p&gt;I’m pleased to say that the full set of updated videos are now available online. Go to &lt;a href="http://channel9.msdn.com/Blogs/egibson/Windows-Phone-7-Jump-Start-Session-1-of-12-Introduction" target="_blank"&gt;Updated! Windows Phone 7 Jump Start (Session 1 of 19)&lt;/a&gt; to see the first page.&lt;/p&gt;  &lt;p&gt;Here’s the full list of videos:&lt;/p&gt;  &lt;p&gt;Updated! &lt;a href="http://channel9.msdn.com/posts/egibson/Windows-Phone-7-Jump-Start-Session-1-of-12-Introduction/"&gt;Session 1: Introduction     &lt;br /&gt;&lt;/a&gt;&lt;a href="http://channel9.msdn.com/posts/egibson/Windows-Phone-7-Jump-Start-Session-2-of-12-Building-a-Silverlight-Application-Part-1/"&gt;Session 2: Building a Silverlight Application, Part 1&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://channel9.msdn.com/posts/egibson/Windows-Phone-7-Jump-Start-Session-3-of-12-Building-a-Silverlight-Application-Part-2/"&gt;Session 3: Building a Silverlight Application, Part 2&lt;/a&gt;    &lt;br /&gt;Updated! &lt;a href="http://channel9.msdn.com/posts/egibson/Windows-Phone-7-Jump-Start-Session-4-of-12-Building-Games-for-the-Windows-Phone-7-Platform/"&gt;Session 4: The Application Bar     &lt;br /&gt;&lt;/a&gt;&lt;a href="http://channel9.msdn.com/posts/egibson/Windows-Phone-7-Jump-Start-Session-5-of-12-Building-XNA-Games-for-the-Windows-Phone-7-Platform-Part-/"&gt;Session 5: Building XNA Games for the Windows Phone 7 Platform, Part 1&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://channel9.msdn.com/posts/egibson/Windows-Phone-7-Jump-Start-Session-6-of-12-Building-XNA-Games-for-the-Windows-Phone-7-Platform-Part-/"&gt;Session 6: Building XNA Games for the Windows Phone 7 Platform, Part 2&lt;/a&gt;    &lt;br /&gt;Updated! &lt;a href="http://channel9.msdn.com/posts/egibson/Windows-Phone-7-Jump-Start-Session-7-of-12-Advanced-Application-Development-Part-1/"&gt;Session 7: Isolation Storage&lt;/a&gt;    &lt;br /&gt;Updated! &lt;a href="http://channel9.msdn.com/posts/egibson/Windows-Phone-7-Jump-Start-Session-8-of-12-Advanced-Application-Development-Part-2/"&gt;Session 8: The Application Lifecycle&lt;/a&gt;    &lt;br /&gt;Updated! &lt;a href="http://channel9.msdn.com/posts/egibson/Windows-Phone-7-Jump-Start-Session-9-of-12-Advanced-Application-Development-Part-3/"&gt;Session 9: Launchers and Choosers&lt;/a&gt;    &lt;br /&gt;Updated! &lt;a href="http://channel9.msdn.com/posts/egibson/Windows-Phone-7-Jump-Start-Session-10-of-12-Marketing-Your-Windows-Phone-7-Application/"&gt;Session 10: Push Notifications&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://channel9.msdn.com/posts/egibson/Windows-Phone-7-Jump-Start-Session-11-of-12-Working-with-Media/"&gt;Session 11: Marketing your Windows Phone Applications&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://channel9.msdn.com/posts/egibson/Windows-Phone-7-Jump-Start-Session-12-of-12-Final-Silverlight-Topics-and-Wrap-Up/"&gt;Session 12: Working with Media&lt;/a&gt;    &lt;br /&gt;New Sessions:    &lt;br /&gt;&lt;a href="http://channel9.msdn.com/posts/Windows-Phone-7-Jump-Start-Session-13-of-19-Panorama-and-Pivots"&gt;Session 13: Panorama and Pivots&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://channel9.msdn.com/posts/Windows-Phone-7-Jump-Start-Session-14-of-19-XNA-Deep-Dive-Part-1"&gt;Session 14: XNA Deep Dive, Part 1&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://channel9.msdn.com/posts/Windows-Phone-7-Jump-Start-Session-15-of-19-XNA-Deep-Dive-Part-2"&gt;Session 15: XNA Deep Dive, Part 2&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://channel9.msdn.com/posts/Windows-Phone-7-Jump-Start-Session-16-of-19-Location-and-Bing-Maps"&gt;Session 16: Location and Bing Maps&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://channel9.msdn.com/posts/Windows-Phone-7-Jump-Start-Session-17-of-19-Optimizing-for-Performance"&gt;Session 17: Optimizing for Performance&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://channel9.msdn.com/posts/Windows-Phone-7-Jump-Start-Session-18-of-19-Designing-Applications-for-Windows-Phone-7-Using-Express"&gt;Session 18: Designing Apps Using Expression Blend &amp;amp; Metro&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://channel9.msdn.com/posts/Windows-Phone-7-Jump-Start-Session-19-of-19-Ask-the-Experts-podcast"&gt;Session 19: Ask the Experts podcast&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=274" width="1" height="1"&gt;</description><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Windows+Phone+7/default.aspx">Windows Phone 7</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/wp7dev/default.aspx">wp7dev</category></item><item><title>New licensing deal for Perst</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2010/10/12/new-licensing-deal-for-perst.aspx</link><pubDate>Tue, 12 Oct 2010 07:27:44 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:253</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>3</slash:comments><description>&lt;p&gt;In the same week that Windows Phone 7 devices and carriers are announced, McObject have announced an attractive new deal for licensing of their Perst database for use in Windows Phone 7 Silverlight applications. Previously, they had insisted on a per-unit license fee but thankfully they are now only requiring a one off charge of $395 per developer which covers free distribution to any number of phones. Note that the database is still free to use for non-commercial applications. You can read more about this in their press release &lt;a href="http://www.mcobject.com/october5/2010"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;img alt="Perst Contacts List" src="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Components.UserFiles/00.00.00.21.04/PerstContactsList.jpg" width="200" height="390" /&gt;&lt;/p&gt;  &lt;p&gt;Well done McObject!&lt;/p&gt;  &lt;p&gt;Perst is an object database that comes as full c# source code and which can be used in a wide range of .NET applications on different platforms. For Windows Phone 7 developers, it is particularly attractive as it works great using Isolated Storage as a backing store.&lt;/p&gt;  &lt;p&gt;I had come across the database when working with one of my Windows Embedded Compact Edition clients and liked its performance and features, so when Windows Phone 7 came along, I wanted to see if it would port to WP7. It did! You can read more about it in my ealrier posts &lt;a href="http://mobileworld.appamundi.com/blogs/andywigley/archive/2010/06/07/perst-a-database-for-windows-phone-7-silverlight.aspx"&gt;here&lt;/a&gt; and &lt;a href="http://mobileworld.appamundi.com/blogs/andywigley/archive/2010/06/08/perst-a-database-for-windows-phone-7-silverlight-part-2.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:7eb81c6a-04b1-4aeb-9dea-434b82a47d00" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/wp7dev" rel="tag"&gt;wp7dev&lt;/a&gt;,&lt;a href="http://technorati.com/tags/silverlight" rel="tag"&gt;silverlight&lt;/a&gt;,&lt;a href="http://technorati.com/tags/windows+phone" rel="tag"&gt;windows phone&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=253" width="1" height="1"&gt;</description><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Windows+Phone+7/default.aspx">Windows Phone 7</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/wp7dev/default.aspx">wp7dev</category></item><item><title>Jump Start Part 2</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2010/09/17/jump-start-part-2.aspx</link><pubDate>Fri, 17 Sep 2010 13:21:50 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:244</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;So following the RTM of the Windows Phone OS a few weeks ago, now the Windows Phone 7 Developer Tools have gone final.&lt;/p&gt;  &lt;p&gt;Lots of good stuff in there since the beta: Pivot and Panorama controls, and the Bing Maps control. Fortunately, we at Appamundi have been working with these as Microsoft have been building them, as we have been one of the privileged ISVs who are building apps ready for launch. Exciting times.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Also exciting is the first release of the Silverlight Toolkit for Windows Phone, providing some of the controls you’ll need that are missing from the ‘official’ controls set. Controls such as a DatePicker and a TimePicker, a WrapPanel, Gesture Recognizer and a ContextMenu – all really useful!&lt;/p&gt;  &lt;p&gt;Best way of learning about all this stuff is to read Brandon’s latest post &lt;a href="http://windowsteamblog.com/windows_phone/b/wpdev/archive/2010/09/16/windows-phone-developer-tools-are-final.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;And we’re doing our bit as well!!&amp;#160; Rob Miles and myself are back in Redmond next week to deliver a follow-up to our phenominally successful video training series. As Brandon says in his post, this &lt;a href="http://channel9.msdn.com/blogs/egibson/windows-phone-7-jump-start-session-1-of-12-introduction"&gt;series of 12 video recordings&lt;/a&gt; have so far notched up 125,000 viewing hours. Awesome!!&lt;/p&gt;  &lt;p&gt;So next Tuesday, we’re doing some more: sessions on the Pivot, Panorama, Bing Maps and Location, and the Silverlight Toolkit. Plus important sessions on building high performance Silverlight apps. Mr. Miles is doing two hours of up to date XNA stuff as well. &lt;a href="https://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032462274&amp;amp;EventCategory=2&amp;amp;culture=en-US&amp;amp;CountryCode=US"&gt;Register here&lt;/a&gt; to join us for session one on Tuesday morning which is the Pivot, Pano, Bing Maps, XNA and Silverlight Toolkit session and &lt;a href="https://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032462275&amp;amp;EventCategory=2&amp;amp;culture=en-US&amp;amp;CountryCode=US"&gt;here&lt;/a&gt; for session 2, which includes the perf, Expression Blend and Live Q&amp;amp;A sessions.&lt;/p&gt;  &lt;p&gt;Hope you can join us!!!&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:2ff25ad8-252e-4b45-af88-2f700d3ed1f3" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/wp7dev" rel="tag"&gt;wp7dev&lt;/a&gt;,&lt;a href="http://technorati.com/tags/silverlight" rel="tag"&gt;silverlight&lt;/a&gt;,&lt;a href="http://technorati.com/tags/windows+phone" rel="tag"&gt;windows phone&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=244" width="1" height="1"&gt;</description><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Windows+Phone+7/default.aspx">Windows Phone 7</category><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/wp7dev/default.aspx">wp7dev</category></item></channel></rss>