<?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</title><link>http://mobileworld.appamundi.com/blogs/andywigley/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2008.5 (Build: 30912.2823)</generator><item><title>TechEd Europe: Windows Phone: MVVM and Unit Testing Step by Step</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2012/06/29/teched-europe-windows-phone-mvvm-and-unit-testing-step-by-step.aspx</link><pubDate>Fri, 29 Jun 2012 11:12:15 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:475</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Thanks to everyone who attended my session this morning at TechEd Europe in Amsterdam.&lt;/p&gt;  &lt;p&gt;I have posted all the sample code I showed up onto Skydrive. You can download it here: &lt;a title="http://sdrv.ms/LUmrgM" href="http://sdrv.ms/LUmrgM"&gt;http://sdrv.ms/LUmrgM&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=475" width="1" height="1"&gt;</description></item><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>Globalizing and Localizing a Windows Phone App</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2012/04/06/globalizing-and-localizing-a-windows-phone-app.aspx</link><pubDate>Fri, 06 Apr 2012 05:29:33 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:457</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;There’s a great post on the Windows Phone Developers Blog on Globalizing and Localizing a Windows Phone App. It’s a great summary of all the good advice that’s out there, but the standout info for me is how to handle different regional variations such as en-US and en-GB, or es-ES and es-MX. I’ve not seen this explained clearly anywhere before – until now!&lt;/p&gt;  &lt;p&gt;Read the blog at &lt;a href="http://windowsteamblog.com/windows_phone/b/wpdev/archive/2012/04/02/globalizing-and-localizing-a-windows-phone-app.aspx"&gt;Globalizing and Localizing a Windows Phone App&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=457" width="1" height="1"&gt;</description></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>Syncing Windows Phone database with backend SQL Server</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2011/12/07/syncing-windows-phone-database-with-backend-sql-server.aspx</link><pubDate>Wed, 07 Dec 2011 12:47:45 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:411</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>9</slash:comments><description>&lt;p&gt;Windows Phone 7 was first released without any local database support which caused raised eyebrows from me and other MVPs who had a background in building Line of Business apps. Over a year ago, I &lt;a href="http://mobileworld.appamundi.com/blogs/andywigley/archive/2010/06/07/perst-a-database-for-windows-phone-7-silverlight.aspx"&gt;posted about a port of the Perst C# database&lt;/a&gt; which had been developed by McObject for a number of&amp;#160; clients including desktop Silverlight. I’m pleased to say that McObject were inspired enough by my efforts to add proper support for Windows Phone 7 into their official download which you can get &lt;a href="http://www.mcobject.com/perst_eval"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;At APPA Mundi, we built and deployed what I’m pretty sure was the first ‘proper’ line of business app for a commercial client in the U.S. in which we populated Perst databases on the server and then copied the database file down to the client. The database has many tens of thousands of records in it, and the app worked – and still works – well. I won’t tell you the name, as you will not be able to find it in marketplace as it is a private distribution.&lt;/p&gt;  &lt;p&gt;Since then, Microsoft has released Windows Phone 7.1 SDK, better known as ‘Mango’, which includes support for LINQ to SQL which you can use to access SQL Server Compact databases on the client. Nonetheless, Perst remains a valuable alternative to L2S and can outperform it in many situations.&lt;/p&gt;  &lt;p&gt;So, now that we have a choice of databases we can use on the client side, the new ‘ask’ that has gone straight to the top of the ‘Requested New Features’ lists is the ability to sync a local database with a backend database. There’s no solution been announced for LINQ to SQL, but &lt;a href="http://www.mcobject.com/november29/2011"&gt;last week McObject announced&lt;/a&gt; that the MediFox company have developed a Perst Sync provider which implements the client-side plumbing for a sync solution built around the Microsoft Sync Framework Toolkit. The PerstSyncProvider synchronization code may be downloaded for free at &lt;a href="http://perstsyncprovider.codeplex.com"&gt;&lt;u&gt;perstsyncprovider.codeplex.com&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The download includes the code for the sync provider and also a simple demo app that shows how you can sync with the sample ListService that you can build from the Microsoft Sync Framework Toolkit. It doesn’t show much in the way of UI, but the code underneath illustrates how easy it is to work with:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://mobileworld.appamundi.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/andywigley/image_5F00_712FEF87.png"&gt;&lt;img style="background-image:none;border-right-width:0px;margin: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_75964A81.png" width="136" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Read more about the Perst Sync provider &lt;a href="http://www.windowsfordevices.com/c/a/News/McObject-PerstSyncProvider/"&gt;here at Windows for Devices&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The &lt;a href="http://code.msdn.microsoft.com/silverlight/Sync-Framework-Toolkit-4dc10f0e"&gt;Microsoft Sync Framework Toolkit&lt;/a&gt; allows you to create your own sync solutions by provisioning a database with the required sync tracking tables and columns and then exposing a WCF sync service to clients. The server side works with SQL Server out of the box, but it should be simple enough to extend to other databases. On the wire, sync is handled by extensions to the OData protocols. Don’t be fooled into thinking it’s a simple click and deploy solution though: this is a *framework* so be prepared to invest some time into this reading the documentation and studying the samples if you want to build your own sync solution. The toolkit comes with sample clients for HTML5, desktop Silverlight, Windows Phone 7 (synchronizing to flat files in Isolated Storage) and Windows Mobile 6.5. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=411" width="1" height="1"&gt;</description><category domain="http://mobileworld.appamundi.com/blogs/andywigley/archive/tags/Sync+Services/default.aspx">Sync Services</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/wp7dev/default.aspx">wp7dev</category></item><item><title>Windows Phone Workshop–Manchester</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2011/09/26/windows-phone-workshop-manchester.aspx</link><pubDate>Mon, 26 Sep 2011 01:35:07 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:405</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Just a very brief note as I’m about to start giving a Windows Phone workshop to Nokia developers in Milan &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_6D7BB9EB.png" /&gt;&lt;/p&gt;  &lt;p&gt;Big thank you to everyone who came to the workshop in Manchester on Saturday 24th September. You were a great and enthusiastic crowd!&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I have started posting up the slides and code &lt;a href="https://skydrive.live.com/redir.aspx?cid=b36de4dd5a9179a1&amp;amp;resid=B36DE4DD5A9179A1!1212"&gt;at this Skydrive share&lt;/a&gt;. Three of the sessions are up there now, and the rest will follow before the end of today.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Thanks for coming to the Workshop!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=405" width="1" height="1"&gt;</description><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>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>FREE GUI add-on for Isolated Storage Explorer</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2011/09/02/free-gui-add-on-for-isolated-storage-explorer.aspx</link><pubDate>Fri, 02 Sep 2011 04:08:19 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:399</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Last week in the JumpStart video webcasts, I showed how you use a new tool that is included in the Windows Phone 7.1 SDK – the Isolated Storage Explorer Tool. This handy tool allows you to list the files in Isolated Storage on the emulator or a develop-unlocked device for an app you are developing, or to copy the files to and from your development PC. It’s very useful but is a command line tool.&lt;/p&gt;  &lt;p&gt;But we all prefer a graphical user interface, don’t we? So here at Appamundi, we’ve built one. My colleague Pete Vickers has already blogged a detailed post all about it, so if you want to learn more, go to &lt;a href="http://mobileworld.appamundi.com/blogs/petevickers/archive/2011/08/31/appa-mundi-release-free-gui-interface-for-the-isolated-storage-explorer-tool-gui-iset.aspx"&gt;Pete&amp;#39;s&amp;#39; post on GUI-ISET&lt;/a&gt; where Pete explains how to get it and how it works.&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=399" width="1" height="1"&gt;</description><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>And we’re back…</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2011/08/12/and-we-re-back.aspx</link><pubDate>Fri, 12 Aug 2011 12:55:57 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:388</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;&lt;b&gt;“Mango” Jump Start! Aug. 23-24! Pass it on…&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;That&amp;#39;s right, Microsoft MVPs &lt;a href="https://mvp.support.microsoft.com/profile=A45C9A02-2624-455A-BD14-7F72733D9756"&gt;Rob Miles&lt;/a&gt; and &lt;a href="https://mvp.support.microsoft.com/profile=1EF31470-6654-4796-9A8E-92767192A78D"&gt;Andy Wigley&lt;/a&gt; are back! Microsoft Learning hosted a &lt;a href="http://channel9.msdn.com/blogs/egibson/windows-phone-7-jump-start-session-1-of-12-introduction"&gt;Windows Phone 7 Jump Start&lt;/a&gt; (plus an update course) last year and it was an absolute smash. Mobile application developers raved about the fast-paced, demo-rich approach, the timeliness of real-world content on new technology, as well as the engaging and often-times humorous delivery. Now that &amp;quot;Mango&amp;quot; has made such a huge splash, they have put together another great course. &lt;/p&gt;  &lt;p&gt;This two-day live virtual class, &lt;strong&gt;&lt;a href="http://bit.ly/Mango-Jump"&gt;Building Applications for Windows Phone Mango Jump Start&lt;/a&gt;&lt;/strong&gt;, is specially tailored for developers looking to build cool applications and games for the new Windows Phone Mango Platform. &lt;/p&gt;  &lt;p&gt;Dates: &lt;strong&gt;August 23-24, 2011&lt;/strong&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;Time: &lt;strong&gt;8:00am – 4:00pm PST&lt;/strong&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;Duration: 8 hours/day, including hour lunch break    &lt;br /&gt;Registration Link: &lt;a href="http://bit.ly/Mango-Jump"&gt;&lt;strong&gt;http://bit.ly/Mango-Jump&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Mango is an important leap forward in Microsoft’s overall mobile strategy and the developer community has taken notice. Now is the time to embrace the “tile-and-app” UI and reap the rewards Mango provides your development team and user community. Here&amp;#39;s an overview of what Rob and Andy will cover:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Day One&lt;/strong&gt; — &lt;em&gt;August 23, 2011 | 8am-5pm PDT | Live online training&lt;/em&gt;&lt;i&gt;     &lt;br /&gt;&lt;/i&gt;• Building Windows Phone Apps with Visual Studio 2010    &lt;br /&gt;• Silverlight on Windows Phone – Introduction    &lt;br /&gt;• Silverlight on Windows Phone – Advanced    &lt;br /&gt;• Using Expression to Build Windows Phone Interfaces    &lt;br /&gt;• Windows Phone Fast Application Switching    &lt;br /&gt;• Windows Phone Multi-tasking &amp;amp; Background Tasks    &lt;br /&gt;• Using Windows Phone Resources (Bing Maps, Camera, etc.) &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Day Two &lt;/strong&gt;— &lt;em&gt;August 24, 2011 | 8am-5pm PDT | Live online training&lt;/em&gt;&lt;i&gt;     &lt;br /&gt;&lt;/i&gt;• Application Data Storage on Windows Phone    &lt;br /&gt;• Using Networks with Windows Phone    &lt;br /&gt;• Windows Azure and Windows Phone     &lt;br /&gt;• Notifications on Windows Phone    &lt;br /&gt;• XNA for Windows Phone     &lt;br /&gt;• Selling a Windows Phone Application&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;What’s a “Jump Start” Course? &lt;/strong&gt;| Training specifically designed for experienced developers and technologists whose jobs demand they know how to best leverage new, emerging Microsoft technologies. These advanced courses assume a certain level of expertise and domain knowledge, so they move quickly and cover topics in a fashion that enables teams to effectively map new skills to real-world situations.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Help us spread the word with this suggested tweet:&lt;/b&gt;    &lt;br /&gt;Mango Jump Start Aug. 23-24! Register for LIVE &amp;amp; FREE expert-led training from @RobMiles &amp;amp; Andy Wigley #wpdev &lt;a href="http://bit.ly/Mango-Jump"&gt;http://bit.ly/Mango-Jump&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=388" width="1" height="1"&gt;</description><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>WP7 Hackathons–Coming Soon to UK!</title><link>http://mobileworld.appamundi.com/blogs/andywigley/archive/2011/03/01/wp7-hackathons-coming-soon-to-uk.aspx</link><pubDate>Tue, 01 Mar 2011 10:14:43 GMT</pubDate><guid isPermaLink="false">989b12f5-6f26-47d9-9f0d-67fe982b88db:342</guid><dc:creator>Andy Wigley</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;Microsoft UK and APPA Mundi are running a series of Windows Phone 7 Hackathon events.&lt;/p&gt;  &lt;p&gt;What’s a Hackathon, you may ask? A Hackathon is an informal event when a group of software developers get together in a spirit of collaboration to push a project forward, to collaborate on development of some reusable code libraries, to get advice from other more experienced developers – and basically to just have some fun producing software!&lt;/p&gt;  &lt;p&gt;The WP7 Hackathons are all about APPS! We want to get as many apps started - and hopefully completed – as possible. We’ll also be working on some open source projects on CodePlex, so if you fancy contributing to an open source WP7 project, you can do that as well. &lt;/p&gt;  &lt;p&gt;The events run for a FULL 24 Hours!! Starting at 6:00pm on a Friday evening and running through to 6:00pm on the Saturday. Of course, you don’t have work through the night if you don’t want to, but you know how it is with programming: once you get your teeth into something, you want to carry on. Well, at our events, you can! We’ll provide plenty of high caffeine beverages and pizza to keep you fueled. Of course, if you only want to come along on the Friday evening, or only on the Saturday, of course you can.&lt;/p&gt;  &lt;p&gt;We’ve got loads of prizes as well!! We’ll be giving away Windows Phone 7 devices, XBox Kinect systems and free software!! Prizes will be awarded for the best app ideas, for the best apps, and for the apps that have progressed the most during the Hackathon event.&lt;/p&gt;  &lt;p&gt;The dates for the first two events and venues are booked, and we’re finalising arrangements for two dates in London. Follow the links below for more info, and to register:&lt;/p&gt;  &lt;p&gt;Manchester Conference Centre, March 18th/19th: &lt;a href="http://developerdeveloperdeveloper.com/wp7hackathon1/Default.aspx"&gt;http://developerdeveloperdeveloper.com/wp7hackathon1/Default.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Birmingham, The Studio, March 25th/26th: &lt;a href="http://developerdeveloperdeveloper.com/wp7hackathon2/Default.aspx"&gt;http://developerdeveloperdeveloper.com/wp7hackathon2/Default.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;London, April 1st/2nd: *TBC*&lt;/p&gt;  &lt;p&gt;London, April 15th/16th: *TBC*&lt;/p&gt;  &lt;p&gt;Come along and join us at the hackathons. Should be a load of fun!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://mobileworld.appamundi.com/aggbug.aspx?PostID=342" width="1" height="1"&gt;</description><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></channel></rss>