<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.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>Delay's Blog : Silverlight</title><link>http://blogs.msdn.com/b/delay/archive/tags/Silverlight/</link><description>Tags: Silverlight</description><dc:language>en</dc:language><generator>Telligent Community 5.6.583.19199 (Build: 5.6.583.19199)</generator><item><title>Know your place in life [Free PlaceImage control makes it easy to add placeholder images to any WPF, Silverlight, or Windows Phone application!]</title><link>http://blogs.msdn.com/b/delay/archive/2011/09/08/know-your-place-in-life-free-placeimage-control-makes-it-easy-to-add-placeholder-images-to-any-wpf-silverlight-or-windows-phone-application.aspx</link><pubDate>Thu, 08 Sep 2011 16:33:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10207954</guid><dc:creator>David Anson</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10207954</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2011/09/08/know-your-place-in-life-free-placeimage-control-makes-it-easy-to-add-placeholder-images-to-any-wpf-silverlight-or-windows-phone-application.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;One of the challenges with referencing online content is that you never know just how long it will take to download... On a good day, images show up immediately and your application has exactly the experience you want. On a bad day, images take a &lt;strong&gt;looong&lt;/strong&gt; time to load - or never load at all! - and your application's interface is full of blank spaces. Applications that make use of remote images need to be prepared for variability like this and should have "placeholder" content to display when the desired image isn't available.&lt;/p&gt;
&lt;p&gt;Of course, there are a variety of ways to deal with this; I thought it would be neat to create a reusable, self-contained class and share it here. I envisioned a simple control that "looked" like a standard &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.image.aspx"&gt;Image&lt;/a&gt; element (i.e., had the same API), but that seamlessly handled the work of displaying placeholder content before an image loaded and getting rid of it afterward. Naturally, I also wanted code that would run on WPF, Silverlight, &lt;strong&gt;and&lt;/strong&gt; Windows Phone! &lt;nobr&gt;:)&lt;/nobr&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;pre style="color: #0000ff;"&gt;&amp;lt;&lt;span style="color: #a31515;"&gt;delay&lt;/span&gt;:&lt;span style="color: #a31515;"&gt;PlaceImage&lt;/span&gt;
&lt;span style="color: #ff0000;"&gt; PlaceholderSource&lt;/span&gt;="PlaceholderPhoto.png"
&lt;span style="color: #ff0000;"&gt; Source&lt;/span&gt;="{&lt;span style="color: #a31515;"&gt;Binding&lt;/span&gt;&lt;span style="color: #ff0000;"&gt; ImageUri&lt;/span&gt;}"/&amp;gt;&lt;/pre&gt;
&lt;p&gt;The result of this exercise is something I've called &lt;code&gt;PlaceImage&lt;/code&gt;. &lt;code&gt;PlaceImage&lt;/code&gt; has the same API as the framework's &lt;code&gt;Image&lt;/code&gt; and can be dropped in pretty much anywhere an &lt;code&gt;Image&lt;/code&gt; is used. To enable the "placeholder" effect, simply set the &lt;code&gt;PlaceholderSource&lt;/code&gt; property to a suitable image. (&lt;strong&gt;Aside&lt;/strong&gt;: While you &lt;em&gt;could&lt;/em&gt; specify another remote image for the placeholder, the most sensible thing to do is to reference an image that's bundled with the application (e.g., as content or a resource).) &lt;code&gt;PlaceImage&lt;/code&gt; immediately shows your placeholder image and waits for the desired image to load - at which point, &lt;code&gt;PlaceImage&lt;/code&gt; swaps it in and gets rid of the placeholder!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I've written a sample application for each of the supported platforms that displays contact cards of imaginary employees. When the sample first runs, none of the remote images have loaded, so each card shows the "?" placeholder image:&lt;/p&gt;
&lt;img alt="PlaceImageDemo on Windows Phone" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-60-92-metablogapi/4747.PlaceImageDemo_2D00_WP.png" width="584" height="336" /&gt;
&lt;p&gt;After a while, some of the remote images will have loaded:&lt;/p&gt;
&lt;img alt="PlaceImageDemo on Silverlight" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-60-92-metablogapi/4834.PlaceImageDemo_2D00_SL.png" width="280" height="402" /&gt;
&lt;p&gt;Eventually, all the remote images load:&lt;/p&gt;
&lt;img alt="PlaceImageDemo on WPF" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-60-92-metablogapi/7077.PlaceImageDemo_2D00_WPF.png" width="254" height="378" /&gt;
&lt;p&gt;&lt;em&gt;&lt;small&gt;Thanks to &lt;a href="http://placekitten.com/"&gt;placekitten&lt;/a&gt; for the handy placeholder images!&lt;/small&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Making use of online content in an application is easy to do and a great way to enrich an application. However, the unpredictable nature of the network means content might not always be available when it's needed. &lt;code&gt;PlaceImage&lt;/code&gt; makes it easy to add placeholder images to common scenarios and helps keep the user interface free of blank spaces. With easy support for WPF, Silverlight, &lt;strong&gt;and&lt;/strong&gt; Windows Phone, you can add it to pretty much &lt;em&gt;any&lt;/em&gt; XAML-based application!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt; &lt;a href="http://cesso.org/Samples/PlaceImageDemo/PlaceImageDemo.zip"&gt;[Click here to download the PlaceImageDemo project which includes PlaceImage.cs and sample applications for WPF, Silverlight, and Windows Phone.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Notes&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Just like &lt;code&gt;Image&lt;/code&gt;, &lt;code&gt;PlaceImage&lt;/code&gt; has properties for &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.image.source.aspx"&gt;Source&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.image.stretch.aspx"&gt;Stretch&lt;/a&gt;, and &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.image.stretchdirection.aspx"&gt;StretchDirection&lt;/a&gt; (the last being available only on WPF). &lt;code&gt;PlaceImage&lt;/code&gt;'s additional &lt;code&gt;PlaceholderSource&lt;/code&gt; property is used just like &lt;code&gt;Source&lt;/code&gt; and identifies the placeholder image to be displayed before the &lt;code&gt;Source&lt;/code&gt; image is available. (So set it to a local image!)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Changes to the &lt;code&gt;Source&lt;/code&gt; property of a loaded &lt;code&gt;Image&lt;/code&gt; immediately clear its contents. Similarly, changing the &lt;code&gt;Source&lt;/code&gt; of a loaded &lt;code&gt;PlaceImage&lt;/code&gt; immediately switches to its placeholder image while the new remote content loads. You can trigger this behavior in the sample application by clicking any kitten.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Because the Silverlight version of the demo application references web content, it needs to be run from the &lt;code&gt;PlaceImageDemoSL&lt;strong&gt;.Web&lt;/strong&gt;&lt;/code&gt; project. (Although running &lt;code&gt;PlaceImageDemoSL&lt;/code&gt; &lt;em&gt;will&lt;/em&gt; show placeholders, the kitten pictures never load.) The MSDN article &lt;a href="http://msdn.microsoft.com/en-us/library/cc189008(v=VS.95).aspx"&gt;URL Access Restrictions in Silverlight&lt;/a&gt; has more information on Silverlight's "cross-scheme access" limitations.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.control.aspx"&gt;Control&lt;/a&gt; subclasses typically live in a dedicated assembly and define their default &lt;a href="http://msdn.microsoft.com/en-us/library/ms745683.aspx"&gt;Style/Template&lt;/a&gt; in &lt;code&gt;Generic.xaml&lt;/code&gt;. This is a great, general-purpose model, but I wanted &lt;code&gt;PlaceImage&lt;/code&gt; to be easy to add to existing projects in source code form, so it does everything in a single file. All you need to do is include &lt;code&gt;PlaceImage.cs&lt;/code&gt; in your project, and &lt;code&gt;PlaceImage&lt;/code&gt; will be available in the &lt;code&gt;Delay&lt;/code&gt; namespace.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The absence of the &lt;code&gt;StretchDirection&lt;/code&gt; property on Silverlight and Windows Phone isn't the only platform difference &lt;code&gt;PlaceImage&lt;/code&gt; runs into: whereas Silverlight and Windows Phone offer the handy &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.image.imageopened(VS.95).aspx"&gt;Image.ImageOpened&lt;/a&gt; event, WPF has only the (more cumbersome) &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource.downloadcompleted.aspx"&gt;BitmapSource.DownloadCompleted&lt;/a&gt; event. The meaning of these two events isn't &lt;em&gt;quite&lt;/em&gt; identical, but for the purposes of &lt;code&gt;PlaceImage&lt;/code&gt;, they're considered equivalent.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10207954" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/WPF/">WPF</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category></item><item><title>Invisible pixels are just as clickable as real pixels! [Tip: Use a Transparent brush to make "empty" parts of a XAML element respond to mouse and touch input]</title><link>http://blogs.msdn.com/b/delay/archive/2011/08/18/invisible-pixels-are-just-as-clickable-as-real-pixels-tip-use-a-transparent-brush-to-make-quot-empty-quot-parts-of-a-xaml-element-respond-to-mouse-and-touch-input.aspx</link><pubDate>Fri, 19 Aug 2011 05:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10197637</guid><dc:creator>David Anson</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10197637</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2011/08/18/invisible-pixels-are-just-as-clickable-as-real-pixels-tip-use-a-transparent-brush-to-make-quot-empty-quot-parts-of-a-xaml-element-respond-to-mouse-and-touch-input.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p class="TipHeader"&gt;Tip&lt;/p&gt;
&lt;p class="TipTip"&gt;Use a Transparent brush to make "empty" parts of a XAML element respond to mouse and touch input&lt;/p&gt;
&lt;p class="TipHeader"&gt;Explanation&lt;/p&gt;
&lt;p&gt;I got a question yesterday and thought the answer would make a good addition to my &lt;a href="http://blogs.msdn.com/b/delay/archive/tags/development+tips/"&gt;Development Tips&lt;/a&gt; series. As you probably know, WPF, Silverlight, and Windows Phone support a rich, hierarchical way of laying out an application's UI. Elements can be created in &lt;a href="http://en.wikipedia.org/wiki/Xaml"&gt;XAML&lt;/a&gt; or in code and respond to input by firing the relevant events (&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.mouseleftbuttondown.aspx"&gt;MouseLeftButtonDown&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.buttonbase.click.aspx"&gt;Click&lt;/a&gt;, etc.). Input events bubble from the element "closest" to the user all the way up to the root element (stopping if an event is marked &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.routedeventargs.handled.aspx"&gt;Handled&lt;/a&gt;). Every now and then someone finds that an element they expect to be getting input is &lt;strong&gt;not&lt;/strong&gt; (and they've made sure none of its children are "eating" the event). The most common reason is that the element doesn't have any pixels for the user to click on! For example, in a 100x100 panel containing a short message, &lt;em&gt;only the text pixels&lt;/em&gt; are considered part of the panel and respond to mouse input - everything else passes "through" the empty area and bubbles up to the parent. This behavior enables the creation of elements with &lt;em&gt;any&lt;/em&gt; shape, but sometimes it's not what you want. Fortunately, it's simple to get empty parts of an element to respond to input: just draw some pixels! And while a &lt;a href="http://msdn.microsoft.com/en-us/library/ms743593.aspx"&gt;Brush&lt;/a&gt; of any color will do the trick, painting with &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.brushes.transparent.aspx"&gt;Transparent&lt;/a&gt; pixels is a fantastic way to keep empty space looking empty while &lt;strong&gt;also&lt;/strong&gt; being clickable!&lt;/p&gt;
&lt;p class="TipHeader"&gt;Good Example&lt;/p&gt;
&lt;pre style="color: #0000ff;"&gt;&amp;lt;&lt;span style="color: #a31515;"&gt;Grid&lt;/span&gt;
    &lt;span style="background-color: yellow;"&gt;&lt;span style="color: #ff0000;"&gt;Background&lt;/span&gt;="Transparent"&lt;/span&gt;
    &lt;span style="color: #ff0000;"&gt;MouseLeftButtonDown&lt;/span&gt;="Grid_MouseLeftButtonDown"&amp;gt;
    &amp;lt;&lt;span style="color: #a31515;"&gt;TextBlock&lt;/span&gt;
        &lt;span style="color: #ff0000;"&gt;Text&lt;/span&gt;="You can click anywhere in the Grid!"
        &lt;span style="color: #ff0000;"&gt;HorizontalAlignment&lt;/span&gt;="Center"
        &lt;span style="color: #ff0000;"&gt;VerticalAlignment&lt;/span&gt;="Center"/&amp;gt;
&amp;lt;/&lt;span style="color: #a31515;"&gt;Grid&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;p class="TipHeader"&gt;More information&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa970904.aspx"&gt;WPF Brushes Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms742806.aspx"&gt;Routed Events Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms745058.aspx"&gt;Layout System&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10197637" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/WPF/">WPF</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Development+Tips/">Development Tips</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category></item><item><title>"Sort" of a follow-up post [IListExtensions class enables easy sorting of .NET list types; today's updates make some scenarios faster or more convenient]</title><link>http://blogs.msdn.com/b/delay/archive/2011/05/18/quot-sort-quot-of-a-follow-up-post-ilistextensions-class-enables-easy-sorting-of-net-list-types-today-s-updates-make-some-scenarios-faster-or-more-convenient.aspx</link><pubDate>Wed, 18 May 2011 17:20:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10165948</guid><dc:creator>David Anson</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10165948</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2011/05/18/quot-sort-quot-of-a-follow-up-post-ilistextensions-class-enables-easy-sorting-of-net-list-types-today-s-updates-make-some-scenarios-faster-or-more-convenient.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;Recently, I wrote a post about the &lt;code&gt;IListExtensions&lt;/code&gt; collection of &lt;a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx"&gt;extension methods&lt;/a&gt; I created to make it easy to maintain a sorted list based on any &lt;a href="http://msdn.microsoft.com/en-us/library/5y536ey6.aspx"&gt;IList(T)&lt;/a&gt; implementation without needing to create a special subclass. In that post, &lt;a href="http://blogs.msdn.com/b/delay/archive/2011/05/04/something-quot-sort-quot-of-handy-ilistextensions-adds-easy-sorting-to-net-list-types-enabling-faster-search-and-removal-too.aspx"&gt;I explained why I implemented IListExtensions the way I did&lt;/a&gt; and outlined some of the benefits for scenarios like using &lt;a href="http://msdn.microsoft.com/en-us/library/ms668604.aspx"&gt;ObservableCollection(T)&lt;/a&gt; for dynamic updates on Silverlight, WPF, and Windows Phone where the underlying class doesn't intrinsically support sorting. A couple of readers followed up with &lt;a href="http://blogs.msdn.com/b/delay/archive/2011/05/04/something-quot-sort-quot-of-handy-ilistextensions-adds-easy-sorting-to-net-list-types-enabling-faster-search-and-removal-too.aspx#comments"&gt;some good questions and clarifications&lt;/a&gt; which I'd encourage having a look for additional context. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;During the time I've been using &lt;code&gt;IListExtensions&lt;/code&gt; in a project of my own, I have noticed two patterns that prompted today's update: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;It's easy to get performant set-like behavior from a sorted list.&lt;/strong&gt; Recall that a &lt;a href="http://en.wikipedia.org/wiki/Set_(computer_science)"&gt;set&lt;/a&gt; is simply a collection in which a particular item appears either 0 or 1 times (i.e., there are no duplicates in the collection). While this invariant can be easily maintained with any sorted list by performing a remove before each add (recall that &lt;a href="http://msdn.microsoft.com/en-us/library/bye7h94w.aspx"&gt;ICollection(T).Remove&lt;/a&gt; (and therefore &lt;code&gt;IListExtensions.RemoveSorted&lt;/code&gt;) doesn't throw if an element is not present), it also means there are &lt;strong&gt;two&lt;/strong&gt; searches of the list every time an item is added: one for the call to &lt;code&gt;RemoveSorted&lt;/code&gt; and another for the call to &lt;code&gt;AddSorted&lt;/code&gt;. While it's possible to be a bit more clever and avoid the extra search &lt;strong&gt;some&lt;/strong&gt;times, the API doesn't let you to "remember" the right index between calls to &lt;code&gt;*Sorted&lt;/code&gt; methods, so you can't get rid of the redundant search every time. &lt;/p&gt;
&lt;p&gt;Therefore, I created the &lt;code&gt;AddOrReplaceSorted&lt;/code&gt; method which has the same signature as &lt;code&gt;AddSorted&lt;/code&gt; (and therefore &lt;a href="http://msdn.microsoft.com/en-us/library/63ywd54z.aspx"&gt;ICollection(T).Add&lt;/a&gt;) and implements the set-like behavior of ensuring there is at most one instance of a particular item (i.e., the &lt;a href="http://msdn.microsoft.com/en-us/library/4d7sx9hd.aspx"&gt;IComparable(T)&lt;/a&gt; search key) present in the collection at any time. Because this one method does everything, it only ever needs to perform a &lt;strong&gt;single&lt;/strong&gt; search of the list and can help save a few CPU cycles in relevant scenarios. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;It's convenient to be able to call &lt;code&gt;RemoveSorted&lt;/code&gt;/&lt;code&gt;IndexOfSorted&lt;/code&gt;/&lt;code&gt;ContainsSorted&lt;/code&gt; with an instance of the search key.&lt;/strong&gt; Recall from the original post that &lt;code&gt;IListExtensions&lt;/code&gt; requires items in the list to implement the &lt;code&gt;IComparable(T)&lt;/code&gt; interface in order to define their sort order. This is fine most of the time, but can require a bit of extra overhead in situations where the items' sort order depends on only some (or commonly just one) of their properties. &lt;/p&gt;
&lt;p&gt;For example, note that the sort order the &lt;code&gt;Person&lt;/code&gt; class below depends only on the &lt;code&gt;Name&lt;/code&gt; property: &lt;/p&gt;
&lt;pre style="color: #000000;"&gt;&lt;span style="color: #0000ff;"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af;"&gt; Person&lt;/span&gt; : &lt;span style="color: #2b91af;"&gt;IComparable&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af;"&gt;Person&lt;/span&gt;&amp;gt;
{
    &lt;span style="color: #0000ff;"&gt;public string&lt;/span&gt; Name { &lt;span style="color: #0000ff;"&gt;get&lt;/span&gt;; &lt;span style="color: #0000ff;"&gt;set&lt;/span&gt;; }
    &lt;span style="color: #0000ff;"&gt;public string&lt;/span&gt; Details { &lt;span style="color: #0000ff;"&gt;get&lt;/span&gt;; &lt;span style="color: #0000ff;"&gt;set&lt;/span&gt;; }

    &lt;span style="color: #0000ff;"&gt;public int&lt;/span&gt; CompareTo(&lt;span style="color: #2b91af;"&gt;Person&lt;/span&gt; other)
    {
        &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; Name.CompareTo(other.Name);
    }
}&lt;/pre&gt;
&lt;p&gt;In this case, using &lt;code&gt;ContainsSorted&lt;/code&gt; on a &lt;code&gt;List(Person)&lt;/code&gt; to search for a particular name would require the creation of a fake &lt;code&gt;Person&lt;/code&gt; instance to pass as the parameter to &lt;code&gt;ContainsSorted&lt;/code&gt; in order to match the type of the underlying collection. This isn't usually a big deal (though it &lt;em&gt;can&lt;/em&gt; be if the class doesn't have a public constructor!), but it complicates the code and seems like it ought to be unnecessary. &lt;/p&gt;
&lt;p&gt;Therefore, I've added new versions of &lt;code&gt;RemoveSorted&lt;/code&gt;/&lt;code&gt;IndexOfSorted&lt;/code&gt;/&lt;code&gt;ContainsSorted&lt;/code&gt; that take a &lt;code&gt;key&lt;/code&gt; parameter and a &lt;code&gt;keySelector&lt;/code&gt; &lt;a href="http://msdn.microsoft.com/en-us/library/bb549151.aspx"&gt;Func(T, K)&lt;/a&gt;. The selector is passed an item from the list and needs to return that item's sort key (the thing that its &lt;a href="http://msdn.microsoft.com/en-us/library/43hc6wht.aspx"&gt;IComparable(T).CompareTo&lt;/a&gt; operates on). Not surprisingly, the underlying type of the keys must implement &lt;code&gt;IComparable(T)&lt;/code&gt;; keys are then compared directly (instead of indirectly via the containing items). In this way, it's possible to look up (or remove) a &lt;code&gt;Person&lt;/code&gt; in a &lt;code&gt;List(Person)&lt;/code&gt; by passing only the person's name and &lt;strong&gt;not&lt;/strong&gt; having to bother with the temporary &lt;code&gt;Person&lt;/code&gt; object at all! &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In addition to the code changes discussed above, I've updated the automated test project that comes with &lt;code&gt;IListExtensions&lt;/code&gt; to cover all the new scenarios. Conveniently, the new implementation of &lt;code&gt;AddOrReplaceSorted&lt;/code&gt; is nearly identical to that of &lt;code&gt;AddSorted&lt;/code&gt; and can be easily validated with &lt;a href="http://msdn.microsoft.com/en-us/library/dd412070.aspx"&gt;SortedSet(T)&lt;/a&gt;. Similarly, the three new key-based methods have all been implemented as variations of the pre-existing methods and &lt;em&gt;those&lt;/em&gt; have been modified to call directly into the new methods. Aside from a bit of clear, deliberate redundancy for &lt;code&gt;AddOrReplaceSorted&lt;/code&gt;, there's hardly any more code in this release than there was in the previous one - yet refactoring the implementation slightly enabled some handy new scenarios! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/IListExtensions/IListExtensions.zip"&gt;[Click here to download the IListExtensions implementation and its complete unit test project.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Proper sorting libraries offer a wide variety of ways to sort, compare, and work with sorted lists. &lt;code&gt;IListExtensions&lt;/code&gt; is &lt;strong&gt;not&lt;/strong&gt; a proper sorting library - nor does it aspire to be one. &lt;nobr&gt;:)&lt;/nobr&gt; Rather, it's a small collection of handy methods that make it easy to incorporate sorting into some common Silverlight, WPF, and Windows Phone scenarios. Sometimes you're forced to use a collection (like &lt;code&gt;ObservableCollection(T)&lt;/code&gt;) that doesn't do everything you want - but if all you're missing is basic sorting functionality, then &lt;code&gt;IListExtensions&lt;/code&gt; just might be the answer! &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10165948" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/WPF/">WPF</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category></item><item><title>Something "sort" of handy... [IListExtensions adds easy sorting to .NET list types - enabling faster search and removal, too!]</title><link>http://blogs.msdn.com/b/delay/archive/2011/05/04/something-quot-sort-quot-of-handy-ilistextensions-adds-easy-sorting-to-net-list-types-enabling-faster-search-and-removal-too.aspx</link><pubDate>Wed, 04 May 2011 16:58:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10161023</guid><dc:creator>David Anson</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10161023</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2011/05/04/something-quot-sort-quot-of-handy-ilistextensions-adds-easy-sorting-to-net-list-types-enabling-faster-search-and-removal-too.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;If you want to display a dynamically changing collection of items in WPF, Silverlight, or Windows Phone, there are a lot of collection classes to pick from - but there's really just &lt;strong&gt;one&lt;/strong&gt; good choice: &lt;a href="http://msdn.microsoft.com/en-us/library/ms668604.aspx"&gt;ObservableCollection(T)&lt;/a&gt;. Although nearly all the &lt;a href="http://msdn.microsoft.com/en-us/library/5y536ey6.aspx"&gt;IList(T)&lt;/a&gt;/&lt;a href="http://msdn.microsoft.com/en-us/library/92t2ye13.aspx"&gt;ICollection(T)&lt;/a&gt;/&lt;a href="http://msdn.microsoft.com/en-us/library/9eekhta0.aspx"&gt;IEnumerable(T)&lt;/a&gt; implementations work well for &lt;em&gt;static&lt;/em&gt; data, &lt;em&gt;dynamic&lt;/em&gt; data only updates automatically when it's in a collection that implements &lt;a href="http://msdn.microsoft.com/en-us/library/system.collections.specialized.inotifycollectionchanged.aspx"&gt;INotifyCollectionChanged&lt;/a&gt;. And while it's possible to write your own &lt;code&gt;INotifyCollectionChanged&lt;/code&gt; code, doing a good job takes a fair amount of work. Fortunately, &lt;code&gt;ObservableCollection(T)&lt;/code&gt; does nearly everything you'd want and is a great choice nearly all of the time. &lt;/p&gt;
&lt;p&gt;Unless you want your data sorted... &lt;/p&gt;
&lt;p&gt;By design, &lt;code&gt;ObservableCollection(T)&lt;/code&gt; doesn't sort data - that's left to the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.data.collectionview.aspx"&gt;CollectionView&lt;/a&gt; class which is the officially recommended way to sort lists for display (for more details, please refer to the &lt;a href="http://msdn.microsoft.com/en-us/library/ms752347.aspx#binding_to_collections"&gt;Data Binding Overview's "Binding to Collections" section&lt;/a&gt;). The way &lt;code&gt;CollectionView&lt;/code&gt; works is to add an additional layer of indirection on top of your list. &lt;strong&gt;That&lt;/strong&gt; gets sorted and the underlying collection isn't modified at all. This is a fine, flexible design (it enables a variety of other scenarios like filtering, grouping, and multiple views), but sometimes it'd be easier if the actual collection were sorted and the extra layer wasn't present (in addition to imposing a bit of overhead, working with &lt;code&gt;CollectionView&lt;/code&gt; requires additional code to account for the indirection). &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So it would be nice if there were a handy way to sort an &lt;code&gt;ObservableCollection(T)&lt;/code&gt; - something like the &lt;a href="http://msdn.microsoft.com/en-us/library/b0zbh7b6.aspx"&gt;List(T).Sort&lt;/a&gt; method. Unfortunately, &lt;code&gt;ObservableCollection(T)&lt;/code&gt; doesn't derive from &lt;code&gt;List(T)&lt;/code&gt;, so it doesn't have that method... Besides, it'd be better if adding items to the list put them in the right place to begin with - instead of adding them to the wrong place and then re-sorting the entire list after the fact. Along the same lines, scenarios that could take advantage of sorting for faster look-ups would benefit from something like &lt;a href="http://msdn.microsoft.com/en-us/library/w4e7fxsh.aspx"&gt;List(T).BinarySearch&lt;/a&gt; - which &lt;strong&gt;also&lt;/strong&gt; doesn't exist on &lt;code&gt;ObservableCollection(T)&lt;/code&gt;. &lt;/p&gt;
&lt;p&gt;All we really need to do here is provide custom implementations of add/remove/contains/index-of for &lt;code&gt;ObservableCollection(T)&lt;/code&gt; and we'd have the best of both worlds. One way of doing that is to subclass - but that ties the code to a specific base class and limits its usefulness somewhat (just like &lt;code&gt;Sort&lt;/code&gt; and &lt;code&gt;BinarySearch&lt;/code&gt; for &lt;code&gt;List(T)&lt;/code&gt; above). What we can do instead is implement these helper methods in a standalone class and enable them to target the least common denominator, &lt;code&gt;IList(T)&lt;/code&gt;, and therefore apply in a &lt;strong&gt;variety&lt;/strong&gt; of scenarios (i.e., all classes that implement that interface). What's more, these helpers can be trivially written as &lt;a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx"&gt;extension methods&lt;/a&gt; so they'll look just like APIs on the underlying classes! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This sounds promising - let's see how it might work by considering the complete &lt;code&gt;IList(T)&lt;/code&gt; interface hierarchy: &lt;/p&gt;
&lt;pre style="color: #000000;"&gt;&lt;span style="color: #0000ff;"&gt;public interface&lt;/span&gt;&lt;span style="color: #2b91af;"&gt; IList&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color: #2b91af;"&gt;ICollection&lt;/span&gt;&amp;lt;T&amp;gt;, &lt;span style="color: #2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;T&amp;gt;, &lt;span style="color: #2b91af;"&gt;IEnumerable
&lt;/span&gt;{
    T &lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;[&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; index] { &lt;span style="color: #0000ff;"&gt;get&lt;/span&gt;; &lt;span style="color: #0000ff;"&gt;set&lt;/span&gt;; }         &lt;span style="color: #008000;"&gt;// Good as-is
&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;    int&lt;/span&gt; IndexOf(T item);                    &lt;span style="color: #008000; background-color: yellow;"&gt;// Okay as-is; could be faster if sorted&lt;/span&gt;
&lt;span style="color: #0000ff;"&gt;    void&lt;/span&gt; Insert(&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; index, T item);         &lt;span style="color: #008000; background-color: yellow;"&gt;// Should NOT be used with a sorted collection (might un-sort it)&lt;/span&gt;
&lt;span style="color: #0000ff;"&gt;    void&lt;/span&gt; RemoveAt(&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; index);               &lt;span style="color: #008000;"&gt;// Good as-is
&lt;/span&gt;}
&lt;span style="color: #0000ff;"&gt;public interface&lt;/span&gt;&lt;span style="color: #2b91af;"&gt; ICollection&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color: #2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;T&amp;gt;, &lt;span style="color: #2b91af;"&gt;IEnumerable
&lt;/span&gt;{
    &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; Count { &lt;span style="color: #0000ff;"&gt;get&lt;/span&gt;; }                      &lt;span style="color: #008000;"&gt;// Good as-is
&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;    bool&lt;/span&gt; IsReadOnly { &lt;span style="color: #0000ff;"&gt;get&lt;/span&gt;; }                &lt;span style="color: #008000;"&gt;// Good as-is
&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;    void&lt;/span&gt; Add(T item);                       &lt;span style="color: #008000; background-color: yellow;"&gt;// Needs custom implementation that preserves sort order&lt;/span&gt;
&lt;span style="color: #0000ff;"&gt;    void&lt;/span&gt; Clear();                           &lt;span style="color: #008000;"&gt;// Good as-is
&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;    bool&lt;/span&gt; Contains(T item);                  &lt;span style="color: #008000; background-color: yellow;"&gt;// Okay as-is; could be faster if sorted&lt;/span&gt;
&lt;span style="color: #0000ff;"&gt;    void&lt;/span&gt; CopyTo(T[] array, &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; arrayIndex); &lt;span style="color: #008000;"&gt;// Good as-is
&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;    bool&lt;/span&gt; Remove(T item);                    &lt;span style="color: #008000; background-color: yellow;"&gt;// Okay as-is; could be faster if sorted&lt;/span&gt;
}
&lt;span style="color: #0000ff;"&gt;public interface&lt;/span&gt;&lt;span style="color: #2b91af;"&gt; IEnumerable&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color: #2b91af;"&gt;IEnumerable
&lt;/span&gt;{
    &lt;span style="color: #2b91af;"&gt;IEnumerator&lt;/span&gt;&amp;lt;T&amp;gt; GetEnumerator();         &lt;span style="color: #008000;"&gt;// Good as-is
&lt;/span&gt;}
&lt;span style="color: #0000ff;"&gt;public interface&lt;/span&gt;&lt;span style="color: #2b91af;"&gt; IEnumerable
&lt;/span&gt;{
    &lt;span style="color: #2b91af;"&gt;IEnumerator&lt;/span&gt; GetEnumerator();            &lt;span style="color: #008000;"&gt;// Good as-is
&lt;/span&gt;}&lt;/pre&gt;
&lt;p&gt;To create a sorted &lt;code&gt;IList(T)&lt;/code&gt;, there's only one method that &lt;strong&gt;needs&lt;/strong&gt; to be written (add) and three others that &lt;strong&gt;should&lt;/strong&gt; be written to take advantage of the sorted collection for better performance (remove, contains, and index-of). (Aside: If you know a list is sorted, finding the right location changes from an &lt;code&gt;O(n)&lt;/code&gt; problem to an &lt;code&gt;O(log n)&lt;/code&gt; problem. &lt;a href="http://en.wikipedia.org/wiki/Big_O_notation"&gt;Read more about "big O" notation here.&lt;/a&gt;) The only additional requirement we'll impose is that the elements of the collection must have a natural order. One way this is commonly done is by implementing the &lt;a href="http://msdn.microsoft.com/en-us/library/4d7sx9hd.aspx"&gt;IComparable(T)&lt;/a&gt; interface on the item class. Basic .NET types already do this, as do other classes in the framework (ex: &lt;a href="http://msdn.microsoft.com/en-us/library/system.datetime.aspx"&gt;DateTime&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.tuple.aspx"&gt;Tuple&lt;/a&gt;, etc.). Because this interface has just one method, it's easy to add - and can often be implemented in terms of &lt;code&gt;IComparable(T)&lt;/code&gt; for its constituent parts! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So here's what the &lt;code&gt;IListExtensions&lt;/code&gt; class I've created looks like: &lt;/p&gt;
&lt;pre style="color: #000000;"&gt;&lt;span style="color: #0000ff;"&gt;static class&lt;/span&gt;&lt;span style="color: #2b91af;"&gt; IListExtensions
&lt;/span&gt;{
    &lt;span style="color: #0000ff;"&gt;public static void&lt;/span&gt; AddSorted&amp;lt;T&amp;gt;(&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;&lt;span style="color: #2b91af;"&gt; IList&lt;/span&gt;&amp;lt;T&amp;gt; list, T item) &lt;span style="color: #0000ff;"&gt;where&lt;/span&gt; T : &lt;span style="color: #2b91af;"&gt;IComparable&lt;/span&gt;&amp;lt;T&amp;gt; { ... }
    &lt;span style="color: #0000ff;"&gt;public static bool&lt;/span&gt; RemoveSorted&amp;lt;T&amp;gt;(&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;&lt;span style="color: #2b91af;"&gt; IList&lt;/span&gt;&amp;lt;T&amp;gt; list, T item) &lt;span style="color: #0000ff;"&gt;where&lt;/span&gt; T : &lt;span style="color: #2b91af;"&gt;IComparable&lt;/span&gt;&amp;lt;T&amp;gt; { ... }
    &lt;span style="color: #0000ff;"&gt;public static int&lt;/span&gt; IndexOfSorted&amp;lt;T&amp;gt;(&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;&lt;span style="color: #2b91af;"&gt; IList&lt;/span&gt;&amp;lt;T&amp;gt; list, T item) &lt;span style="color: #0000ff;"&gt;where&lt;/span&gt; T : &lt;span style="color: #2b91af;"&gt;IComparable&lt;/span&gt;&amp;lt;T&amp;gt; { ... }
    &lt;span style="color: #0000ff;"&gt;public static bool&lt;/span&gt; ContainsSorted&amp;lt;T&amp;gt;(&lt;span style="color: #0000ff;"&gt;this&lt;/span&gt;&lt;span style="color: #2b91af;"&gt; IList&lt;/span&gt;&amp;lt;T&amp;gt; list, T item) &lt;span style="color: #0000ff;"&gt;where&lt;/span&gt; T : &lt;span style="color: #2b91af;"&gt;IComparable&lt;/span&gt;&amp;lt;T&amp;gt; { ... }
}&lt;/pre&gt;
&lt;p&gt;You can use it to create and manage a sorted &lt;code&gt;ObservableCollection(T)&lt;/code&gt; simply by adding "Sorted" to the code you already have! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/IListExtensions/IListExtensions.zip"&gt;[Click here to download the IListExtensions implementation and its complete unit test project.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;One downside to the extension method approach is that the existing &lt;code&gt;List(T)&lt;/code&gt; methods remain visible and can be called by code that doesn't know to use the &lt;code&gt;*Sorted&lt;/code&gt; versions instead. For &lt;code&gt;Contains&lt;/code&gt;, &lt;code&gt;IndexOf&lt;/code&gt;, and &lt;code&gt;Remove&lt;/code&gt;, this is inefficient, but will still yield the correct answer - but for &lt;code&gt;Add&lt;/code&gt; and &lt;code&gt;Insert&lt;/code&gt; it's a &lt;strong&gt;bug&lt;/strong&gt; because these two methods are likely to ruin the sorted nature of the list when used without care. Once a list becomes unsorted, the &lt;code&gt;*Sorted&lt;/code&gt; methods will return incorrect results because they optimize searches based on the assumption that the list is correctly sorted. Subclassing would be the obvious "solution" to this problem, but it's not a good option here because the original methods aren't &lt;a href="http://msdn.microsoft.com/en-us/library/9fkccyh4.aspx"&gt;virtual&lt;/a&gt; on &lt;code&gt;ObservableCollection(T)&lt;/code&gt;... &lt;/p&gt;
&lt;p&gt;I'm not aware of a good way to make things foolproof without giving up on the nice generality benefits of the current approach, so this seems like one of those times where you just need to be careful about what you're doing. Fortunately, most programs probably only call the relevant methods a couple of times, so it's pretty easy to visit all the call sites and change them to use the corresponding &lt;code&gt;*Sorted&lt;/code&gt; method instead. [Trust me, I've done this myself. &lt;nobr&gt;:)&lt;/nobr&gt; ] &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: There's a subtle ambiguity regarding what to do if the collection contains duplicate items (i.e., multiple items that sort to the same location). It doesn't seem like it will matter most of the time, so &lt;code&gt;IListExtensions&lt;/code&gt; takes the performant way out and returns the &lt;em&gt;first&lt;/em&gt; correct answer it finds. It's important to note this is not necessarily the &lt;em&gt;first&lt;/em&gt; of a group of duplicate items, nor the &lt;em&gt;last&lt;/em&gt; of them - nor will it always be the same one of them! Basically, if the items' &lt;code&gt;IComparable(T)&lt;/code&gt; implementation says two items are equivalent, then &lt;code&gt;IListExtensions&lt;/code&gt; assumes they are and that they're equally valid answers. If the distinction matters in &lt;strong&gt;your&lt;/strong&gt; scenario, please feel free to tweak this code and take the corresponding performance hit. &lt;nobr&gt;:)&lt;/nobr&gt; (Alternatively, if the items' &lt;code&gt;IComparable(T)&lt;/code&gt; implementation can be modified to distinguish between otherwise "identical" items, the underlying ambiguity will be resolved and things will be deterministic again.) &lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It's usually best to leverage platform support for something when it's available, so please look to &lt;code&gt;CollectionView&lt;/code&gt; for your sorting needs in WPF, Silverlight, and Windows Phone applications. But if you end up in a situation where it'd be better to maintain a sorted list yourself, maybe &lt;code&gt;IListExtensions&lt;/code&gt; is just what you need! &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10161023" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/WPF/">WPF</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category></item><item><title>Don't shoot the messenger [A WebBrowserExtensions workaround for Windows Phone and a BestFitPanel tweak for infinite layout bounds on Windows Phone/Silverlight/WPF]</title><link>http://blogs.msdn.com/b/delay/archive/2011/04/20/don-t-shoot-the-messenger-a-webbrowserextensions-workaround-for-windows-phone-and-a-bestfitpanel-tweak-for-infinite-layout-bounds-on-windows-phone-silverlight-wpf.aspx</link><pubDate>Wed, 20 Apr 2011 20:50:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10156411</guid><dc:creator>David Anson</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10156411</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2011/04/20/don-t-shoot-the-messenger-a-webbrowserextensions-workaround-for-windows-phone-and-a-bestfitpanel-tweak-for-infinite-layout-bounds-on-windows-phone-silverlight-wpf.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;One of the neat things about sharing code with the community is hearing how people have learned from it or are using it in their own work. Of course, the more people use something, the more likely they are to identify problems with it - which is &lt;strong&gt;great&lt;/strong&gt; because it provides an opportunity to improve things! This blog post is about addressing two issues that came up around some code I published recently. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Platform Workaround (WebBrowserExtensions)&lt;/strong&gt; &lt;/p&gt;
&lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/3173.WebBrowserExtensions_2D00_WP.png" alt="WebBrowserExtensions on Windows Phone" style="float:right" /&gt;
&lt;p&gt;&lt;a href="https://twitter.com/rogerguess"&gt;Roger Guess&lt;/a&gt; contacted me a couple of days after &lt;a href="http://blogs.msdn.com/b/delay/archive/2011/04/14/quot-those-who-cannot-remember-the-past-are-condemned-to-repeat-it-quot-webbrowserextensions-stringsource-attached-dependency-property-makes-silverlight-windows-phone-wpf-s-webbrowser-control-more-xaml-and-binding-friendly.aspx"&gt;I posted the WebBrowserExtensions code&lt;/a&gt; to report a problem he saw when using it on Windows Phone 7 with the platform's &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.navigation.navigationservice(v=VS.95).aspx"&gt;NavigationService&lt;/a&gt; in a scenario where the user could hit the Back button to return to a page with a &lt;a href="http://msdn.microsoft.com/en-us/library/cc491073(v=VS.95).aspx"&gt;WebBrowser&lt;/a&gt; control that had its content set by the &lt;code&gt;WebBrowserExtensions.StringSource&lt;/code&gt; property. (Whew!) Instead of seeing the content that was there before, the control was &lt;strong&gt;blank&lt;/strong&gt;! Sure enough, I was able to duplicate the problem after I knew the setup... &lt;/p&gt;
&lt;p&gt;My initial theory was that the &lt;code&gt;WebBrowser&lt;/code&gt; was discarding its content during the navigation and not being reinitialized properly when it came back into view. Sure enough, some quick testing &lt;strong&gt;confirmed&lt;/strong&gt; this was the case - and what's more, the same problem happens with the official &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.source(v=VS.95).aspx"&gt;Source&lt;/a&gt; property as well! That made me feel a little better because it suggests a bug with the platform's &lt;code&gt;WebBrowser&lt;/code&gt; control rather than my own code. &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;p&gt;The workaround I came up with for &lt;code&gt;StringSource&lt;/code&gt; (and that was kindly verified by Roger) should work just as well for the official &lt;code&gt;Source&lt;/code&gt; property: I created an application-level event handler for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.loaded(v=VS.95).aspx"&gt;Loaded&lt;/a&gt; event on the &lt;code&gt;WebBrowser&lt;/code&gt; and use that event to re-apply the correct content during the "back" navigation. I updated the Windows Phone sample application and added a new button/page to demonstrate the fix in action. &lt;/p&gt;
&lt;p&gt;If this scenario is possible with &lt;strong&gt;your&lt;/strong&gt; application, please consider applying a similar workaround! &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: Although it should be possible to apply the workaround to the &lt;code&gt;WebBrowserExtensions&lt;/code&gt; code itself, I decided that wasn't ideal because of the event handler: the entire &lt;code&gt;StringSource&lt;/code&gt; attached dependency property implementation is &lt;a href="http://msdn.microsoft.com/en-us/library/98f28cdx(v=VS.100).aspx"&gt;static&lt;/a&gt;, and tracking per-instance data from static code can be tricky. In this case, it would be necessary to ensure the &lt;code&gt;Loaded&lt;/code&gt; event handler was added only once, that it was removed when necessary, and that it didn't introduce any &lt;a href="http://blogs.msdn.com/b/delay/archive/2009/03/09/controls-are-like-diapers-you-don-t-want-a-leaky-one-implementing-the-weakevent-pattern-on-silverlight-with-the-weakeventlistener-class.aspx"&gt;memory leaks&lt;/a&gt;. Because such logic is often &lt;em&gt;much&lt;/em&gt; easier at the application level &lt;strong&gt;and&lt;/strong&gt; because the same basic workaround is necessary for the official &lt;code&gt;WebBrowser.Source&lt;/code&gt; property &lt;strong&gt;and&lt;/strong&gt; because it applies only to Windows Phone, it seemed best to leave the core &lt;code&gt;WebBrowserExtensions&lt;/code&gt; implementation as-is. &lt;/blockquote&gt;
&lt;blockquote&gt;&lt;strong&gt;Further aside&lt;/strong&gt;: This same scenario works fine on Silverlight 4, so it's another example of a Windows Phone quirk that needs to be worked around. (Recall from the &lt;a href="http://blogs.msdn.com/b/delay/archive/2011/04/14/quot-those-who-cannot-remember-the-past-are-condemned-to-repeat-it-quot-webbrowserextensions-stringsource-attached-dependency-property-makes-silverlight-windows-phone-wpf-s-webbrowser-control-more-xaml-and-binding-friendly.aspx"&gt;previous post&lt;/a&gt; that it was already necessary to work around the fact that the Windows Phone &lt;code&gt;WebBrowser&lt;/code&gt; implementation can't be touched outside the visual tree.) That's a shame because the scenario itself is reasonable and consistent with the platform recommendation to use &lt;code&gt;NavigationService&lt;/code&gt; for everything. The fact that it seems broken for the "real" &lt;code&gt;Source&lt;/code&gt; property as well makes me think other people will run into this, too. &lt;nobr&gt;:(&lt;/nobr&gt; &lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/WebBrowserExtensions/WebBrowserExtensions.zip"&gt;[Click here to download the WebBrowserExtensions class and samples for Silverlight, Windows Phone, and WPF.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Layout Implementation Oversight (BestFitPanel)&lt;/strong&gt; &lt;/p&gt;
&lt;p&gt;&lt;a href="https://twitter.com/EitanGabay76"&gt;Eitan Gabay&lt;/a&gt; contacted me soon after &lt;a href="http://blogs.msdn.com/b/delay/archive/2011/03/30/each-one-is-the-best-for-different-definitions-of-quot-best-quot-the-bestfitpanel-collection-of-layout-containers-provides-flexible-easy-to-use-options-for-silverlight-wpf-and-windows-phone-applications.aspx"&gt;I posted my BestFitPanel code&lt;/a&gt; to report an exception he saw when using one of the &lt;code&gt;BestFitPanel&lt;/code&gt; classes as the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemspanel.aspx"&gt;ItemsPanel&lt;/a&gt; of a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox.aspx"&gt;ListBox&lt;/a&gt; at design-time. I hadn't tried that particular configuration, but once I did, I saw the same message: &lt;code&gt;"MeasureOverride of element 'Delay.MostBigPanel' should not return PositiveInfinity or NaN as its DesiredSize."&lt;/code&gt;. If you've dealt much with custom &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.aspx"&gt;Panel&lt;/a&gt; implementations, this probably isn't all that surprising... Although coding layout is often straightforward, there can be a variety of edge cases depending on how the layout is done. (For example: only one child, no children, no available size, nested inside different kinds of parent containers, etc..) &lt;/p&gt;
&lt;p&gt;In this case, it turns out that the constraint passed to &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.measureoverride.aspx"&gt;MeasureOverride&lt;/a&gt; included a value of &lt;a href="http://msdn.microsoft.com/en-us/library/system.double.positiveinfinity.aspx"&gt;double.PositiveInfinity&lt;/a&gt; and &lt;code&gt;BestFitPanel&lt;/code&gt; was returning that same value. That isn't allowed because the &lt;code&gt;MeasureOverride&lt;/code&gt; method of an element is supposed to return the smallest size the element can occupy without clipping - and &lt;strong&gt;nothing&lt;/strong&gt; should require infinite size! (If you think about it, though, the scenario is a little wacky for &lt;code&gt;BestFitPanel&lt;/code&gt;: what does it mean to make the best use of an infinite amount of space?) &lt;/p&gt;
&lt;p&gt;There are two parts to my fix for this problem. The first part is to skip calling the &lt;code&gt;CalculateBestFit&lt;/code&gt; override for infinite bounds (it's unlikely to know what to do anyway) and to &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.measure.aspx"&gt;Measure&lt;/a&gt; all the children at the provided size instead. This ensures all children get a chance to measure during the measure pass - which some controls &lt;strong&gt;require&lt;/strong&gt; in order to render correctly. The second part of the fix is to return a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.size.aspx"&gt;Size&lt;/a&gt; with the longest width and height of any child measured when infinite bounds are passed in. Because children are subject to the same rule about not returning an infinite value from &lt;code&gt;Measure&lt;/code&gt;, this approach means &lt;code&gt;BestFitPanel&lt;/code&gt; won't either &lt;strong&gt;and&lt;/strong&gt; that the &lt;code&gt;Panel&lt;/code&gt; will occupy an amount of space that's related to the size of its content (instead of being arbitrary like 0x0, 100x100, etc.). &lt;/p&gt;
&lt;p&gt;The combined effect of these changes is to fix the reported exception, provide a better design-time experience, and offer an more versatile run-time experience as well! &lt;/p&gt;
&lt;img height="348" width="614" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/6327.BestFitPanel_2D00_All.png" alt="All BestFitPanels overlapped" /&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/BestFitPanel/BestFitPanel.zip"&gt;[Click here to download the source code for all BestFitPanels along with sample projects for Silverlight, WPF, and Windows Phone.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The more a piece of code gets looked at and used, the more likely it is that potential problems are uncovered. It can be difficult to catch everything on your own, so it's &lt;strong&gt;fantastic&lt;/strong&gt; to have a community of people looking at stuff and providing feedback when something doesn't work. Thanks again to Robert and Eitan for bringing these issues to my attention and for taking the time to try out early versions of each fix! &lt;/p&gt;
&lt;p&gt;I'm always hopeful people won't have problems with my code - but when they &lt;strong&gt;do&lt;/strong&gt;, I &lt;em&gt;really&lt;/em&gt; appreciate them taking the time to let me know! &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10156411" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/WPF/">WPF</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category></item><item><title>"Those who cannot remember the past are condemned to repeat it." [WebBrowserExtensions.StringSource attached dependency property makes Silverlight/Windows Phone/WPF's WebBrowser control more XAML- and binding-friendly]</title><link>http://blogs.msdn.com/b/delay/archive/2011/04/14/quot-those-who-cannot-remember-the-past-are-condemned-to-repeat-it-quot-webbrowserextensions-stringsource-attached-dependency-property-makes-silverlight-windows-phone-wpf-s-webbrowser-control-more-xaml-and-binding-friendly.aspx</link><pubDate>Thu, 14 Apr 2011 18:02:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10154060</guid><dc:creator>David Anson</dc:creator><slash:comments>10</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10154060</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2011/04/14/quot-those-who-cannot-remember-the-past-are-condemned-to-repeat-it-quot-webbrowserextensions-stringsource-attached-dependency-property-makes-silverlight-windows-phone-wpf-s-webbrowser-control-more-xaml-and-binding-friendly.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/cc491073(v=VS.95).aspx"&gt;WebBrowser&lt;/a&gt; control is available in Silverlight 4, Windows Phone 7, and all versions of WPF. It's mostly the same everywhere, though there are &lt;a href="http://msdn.microsoft.com/en-us/library/ff431795(v=VS.92).aspx"&gt;some specific differences to keep in mind&lt;/a&gt; when using it on Silverlight-based platforms. &lt;code&gt;WebBrowser&lt;/code&gt; offers two ways to provide its content: by passing a &lt;a href="http://en.wikipedia.org/wiki/Uniform_Resource_Identifier"&gt;URI&lt;/a&gt; or by passing a string with &lt;a href="http://en.wikipedia.org/wiki/Html"&gt;HTML&lt;/a&gt; text: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;If you have a URI, you can set the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.source(v=VS.95).aspx"&gt;Source&lt;/a&gt; (dependency) property in code or &lt;a href="http://en.wikipedia.org/wiki/Xaml"&gt;XAML&lt;/a&gt; &lt;strong&gt;or&lt;/strong&gt; you can call the &lt;a href="http://msdn.microsoft.com/en-us/library/cc491011(v=VS.95).aspx"&gt;Navigate(Uri)&lt;/a&gt; method from code. &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: It's not clear to me what the &lt;code&gt;Navigate(Uri)&lt;/code&gt; method enables that the &lt;code&gt;Source&lt;/code&gt; property doesn't, but flexibility is nice, so I won't dwell on this. &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;On the other hand, if you have a string, your &lt;strong&gt;only&lt;/strong&gt; option is to call the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.navigatetostring(v=VS.95).aspx"&gt;NavigateToString(string)&lt;/a&gt; method from code. &lt;/p&gt;
&lt;p&gt;XAML and data-binding support for strings? &lt;em&gt;Nope, not so much...&lt;/em&gt; &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I'm not sure why all three platforms have the same limitation, but I suspect there was a good reason at some point in time and maybe nobody has revisited the decision since then. Be that as it may, the brief research I did before writing this post suggests that a good number of people have been inconvenienced by the issue. Therefore, I've written a simple &lt;a href="http://msdn.microsoft.com/en-us/library/ms749011.aspx"&gt;attached dependency property&lt;/a&gt; to add support for providing HTML strings in XAML via &lt;a href="http://msdn.microsoft.com/en-us/library/ms752347.aspx"&gt;data binding&lt;/a&gt;! &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;phone&lt;/span&gt;:&lt;span style="color:#a31515"&gt;WebBrowser&lt;/span&gt;&lt;span style="color:#ff0000"&gt; delay&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;WebBrowserExtensions.StringSource&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;Binding&lt;/span&gt;&lt;span style="color:#ff0000"&gt; MyProperty&lt;/span&gt;}"/&amp;gt;&lt;/pre&gt;
&lt;p&gt;As you can see above, this functionality is made possible by the &lt;code&gt;StringSource&lt;/code&gt; property which is exposed by the &lt;code&gt;WebBrowserExtensions&lt;/code&gt; class. It's a fairly simple attached property that just passes its new value on to the &lt;code&gt;WebBrowser&lt;/code&gt;'s &lt;code&gt;NavigateToString&lt;/code&gt; method to do the &lt;strong&gt;real&lt;/strong&gt; work. For everyone's convenience, I've tried to make sure my &lt;code&gt;StringSource&lt;/code&gt; implementation works on Silverlight 4, Windows Phone 7, and WPF. &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: The &lt;code&gt;StringSource&lt;/code&gt; property is read/write from code and XAML, but does &lt;strong&gt;not&lt;/strong&gt; attempt to detect &lt;code&gt;WebBrowser&lt;/code&gt; navigation by other means (and somehow "transform" the results into a corresponding HTML string). Therefore, if you're interleaving multiple navigation methods in the same application, reading from &lt;code&gt;StringSource&lt;/code&gt; &lt;em&gt;may not&lt;/em&gt; be correct - but writing to it should always work! &lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Aside&lt;/strong&gt;: Things are more complicated on Windows Phone because the &lt;code&gt;WebBrowser&lt;/code&gt; implementation there throws exceptions if it gets touched outside the visual tree. Therefore, if &lt;code&gt;WINDOWS_PHONE&lt;/code&gt; is defined (and by default it &lt;strong&gt;is&lt;/strong&gt; for phone projects), this code catches the possible &lt;a href="http://msdn.microsoft.com/en-us/library/system.invalidoperationexception(v=VS.95).aspx"&gt;InvalidOperationException&lt;/a&gt; and deals with it by creating a handler for the &lt;code&gt;WebBrowser&lt;/code&gt;'s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.loaded(v=VS.95).aspx"&gt;Loaded&lt;/a&gt; event that attempts to re-set the string once the control is known to be in the visual tree. If the second attempt fails, the exception is allowed to bubble out of the method. This seems to work nicely for the typical "string in XAML" scenario, though it's possible more complex scenarios will require a more involved workaround. &lt;/p&gt;
&lt;p&gt;My thanks go out to &lt;a href="https://twitter.com/rogerguess"&gt;Roger Guess&lt;/a&gt; for trying an early version of the code and reminding me of this gotcha! &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To prove to ourselves that &lt;code&gt;StringSource&lt;/code&gt; behaves as we intend, let's create the world's simplest &lt;a href="http://en.wikipedia.org/wiki/Rss"&gt;RSS&lt;/a&gt; reader! All it will do is download a single RSS feed, parse it for the titles and content of each post, and display those titles in a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox.aspx"&gt;ListBox&lt;/a&gt;. There'll be a &lt;code&gt;WebBrowser&lt;/code&gt; control using &lt;code&gt;StringSource&lt;/code&gt; to bind to the ListBox's &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector.selecteditem.aspx"&gt;SelectedItem&lt;/a&gt; property (all XAML; no code!), so that when a title is clicked, its content will &lt;strong&gt;automatically&lt;/strong&gt; be displayed by the &lt;code&gt;WebBrowser&lt;/code&gt;! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here's what it looks like on Silverlight (note that the sample must be run outside the browser because of &lt;a href="http://msdn.microsoft.com/en-us/library/cc645032(VS.95).aspx"&gt;network security access restrictions in Silverlight&lt;/a&gt;): &lt;/p&gt;
&lt;img height="353" width="618" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/4643.WebBrowserExtensions_2D00_SL.png" alt="WebBrowserExtensions on Silverlight" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And here's the same code running on Windows Phone: &lt;/p&gt;
&lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/3173.WebBrowserExtensions_2D00_WP.png" alt="WebBrowserExtensions on Windows Phone" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And on WPF: &lt;/p&gt;
&lt;img height="366" width="624" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/5040.WebBrowserExtensions_2D00_WPF.png" alt="WebBrowserExtensions on WPF" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/WebBrowserExtensions/WebBrowserExtensions.zip"&gt;[Click here to download the WebBrowserExtensions class and the samples above for Silverlight, Windows Phone, and WPF.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;StringSource&lt;/code&gt; attached dependency property is simple code for a simple purpose. It doesn't have a lot of bells and whistles, but it gets the job done nicely and fills a small gap in the platform. You won't always deal with HTML content directly, but when you &lt;strong&gt;do&lt;/strong&gt;, &lt;code&gt;StringSource&lt;/code&gt; makes it easy to combine the &lt;code&gt;WebBrowser&lt;/code&gt; control with XAML and data binding! &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10154060" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/WPF/">WPF</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category></item><item><title>Each one is the best - for different definitions of "best" [The BestFitPanel collection of layout containers provides flexible, easy-to-use options for Silverlight, WPF, and Windows Phone applications]</title><link>http://blogs.msdn.com/b/delay/archive/2011/03/30/each-one-is-the-best-for-different-definitions-of-quot-best-quot-the-bestfitpanel-collection-of-layout-containers-provides-flexible-easy-to-use-options-for-silverlight-wpf-and-windows-phone-applications.aspx</link><pubDate>Wed, 30 Mar 2011 17:32:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10147845</guid><dc:creator>David Anson</dc:creator><slash:comments>13</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10147845</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2011/03/30/each-one-is-the-best-for-different-definitions-of-quot-best-quot-the-bestfitpanel-collection-of-layout-containers-provides-flexible-easy-to-use-options-for-silverlight-wpf-and-windows-phone-applications.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;Just over a year ago, &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/02/11/this-one-time-at-band-camp-a-banded-stackpanel-implementation-for-silverlight-and-wpf.aspx#9964178"&gt;a couple of readers asked me&lt;/a&gt; about a WPF/Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.aspx"&gt;Panel&lt;/a&gt; that arranged things to make "best use" of available space &lt;em&gt;without&lt;/em&gt; requiring the developer to set a bunch of stuff up in advance or know how many child elements there would be. Interestingly, this is not a scenario the default &lt;code&gt;Panel&lt;/code&gt; implementations handle particularly well... &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.grid.aspx"&gt;Grid&lt;/a&gt; [WPF/SL/WP] is capable of pretty much anything, but requires the developer to explicitly specify how everything lines up relative to the rows and columns they must manually define. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.stackpanel.aspx"&gt;StackPanel&lt;/a&gt; [WPF/SL/WP] arranges an arbitrary number of items in a tightly-packed line, but overflows when there are too many and leaves empty space when there are too few. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.aspx"&gt;Canvas&lt;/a&gt; [WPF/SL/WP] provides the ultimate in flexibility, but contains absolutely &lt;strong&gt;no&lt;/strong&gt; layout logic and pushes all that overhead onto the developer. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.wrappanel.aspx"&gt;WrapPanel&lt;/a&gt; [WPF/&lt;a href="http://silverlight.codeplex.com/"&gt;SLTK&lt;/a&gt;/&lt;a href="http://silverlight.codeplex.com/"&gt;WPTK&lt;/a&gt;] flows its elements "book-style" left-to-right, top-to-bottom, but runs content off the screen when there's not enough room and can size things surprisingly unless you tell it how big items should be. &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: When scrolling content that doesn't fit is acceptable, &lt;code&gt;WrapPanel&lt;/code&gt; can be quite a good choice. And if you like the idea, but want something a little more aesthetically pleasing, please have a look at my &lt;a href="http://blogs.msdn.com/b/delay/archive/2009/12/08/that-s-a-wrappanel-and-i-am-outta-here-a-balanced-wrappanel-implementation-for-silverlight-and-wpf.aspx"&gt;BalancedWrapPanel&lt;/a&gt; &lt;a href="http://blogs.msdn.com/b/delay/archive/2009/12/13/wrap-music-a-more-flexible-balanced-wrappanel-implementation-for-silverlight-and-wpf.aspx"&gt;implementation&lt;/a&gt;... &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/blockquote&gt;
&lt;blockquote&gt;&lt;strong&gt;Further aside&lt;/strong&gt;: On the other hand, if you're looking for something more like a &lt;code&gt;StackPanel&lt;/code&gt; but with multiple columns (or rows), you might instead be interested in my &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/02/11/this-one-time-at-band-camp-a-banded-stackpanel-implementation-for-silverlight-and-wpf.aspx"&gt;BandedStackPanel implementation&lt;/a&gt;. &lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.dockpanel.aspx"&gt;DockPanel&lt;/a&gt; [WPF/SLTK] crams everything against the edge of its layout slot and leaves a big "chunk" in the center for whatever element is lucky enough to end up there. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.uniformgrid.aspx"&gt;UniformGrid&lt;/a&gt; [WPF] does okay at sensible layout without a lot of fuss - but its default behavior can leave a lot of blank space and so it's best if you tell it in advance how many items there are. &lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;That said, &lt;em&gt;please&lt;/em&gt; don't get me wrong: I'm not complaining about the default set of layout containers - I think they're all good at what they do! However, in the context of the original "just do the right thing for me" scenario, none of them quite seems &lt;strong&gt;ideal&lt;/strong&gt;. &lt;/p&gt;
&lt;p&gt;So when this question came up before, I mentioned I'd written some code that seemed pretty relevant, but that it was for &lt;a href="http://en.wikipedia.org/wiki/Windows_Forms"&gt;Windows Forms&lt;/a&gt; and therefore didn't map cleanly to the different layout model used by Silverlight and WPF. Soon thereafter, I created a sample project to implement a "best fit" panel for Silverlight and WPF (and got nearly all the code written!) - but then found myself distracted by other topics and never managed to write it up formally... &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Until now! &lt;/p&gt;
&lt;p&gt;Today I'm sharing the three &lt;code&gt;Panel&lt;/code&gt; classes I originally wrote for Silverlight and WPF, two abstract base classes they're built on, an extra &lt;code&gt;Panel&lt;/code&gt; I wrote just for this post &lt;em&gt;and&lt;/em&gt; a Windows Phone 7 sample application! (Because this code supports Silverlight 3, it works just as well on the phone as on the desktop.) Hopefully the extra goodness in today's release will offset the delay in posting it... &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The foundation for everything, &lt;code&gt;BestFitPanel&lt;/code&gt; is an abstract base class that implements &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.measureoverride.aspx"&gt;MeasureOverride&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.arrangeoverride.aspx"&gt;ArrangeOverride&lt;/a&gt; to arrange its children in a grid that's &lt;em&gt;M&lt;/em&gt; columns wide and &lt;em&gt;N&lt;/em&gt; rows high. What's nice is that the values of &lt;em&gt;M&lt;/em&gt; and &lt;em&gt;N&lt;/em&gt; are left to subclasses to define by overriding the &lt;code&gt;CalculateBestFit&lt;/code&gt; method. Therefore, a subclass only needs to worry about columns/rows and the base class only needs to worry about handling layout. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;MostBigPanel&lt;/code&gt; is a &lt;code&gt;BestFitPanel&lt;/code&gt; subclass that figures out which values of &lt;em&gt;M&lt;/em&gt; and &lt;em&gt;N&lt;/em&gt; maximize the length of the smaller dimension (be it width or height) of each item. In other words, it avoids long, skinny rectangles in favor of more evenly proportioned ones. &lt;/p&gt;
&lt;img height="348" width="614" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/2570.BestFitPanel_2D00_Big.png" alt="MostBigPanel" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;MostFullPanel&lt;/code&gt; is a &lt;code&gt;BestFitPanel&lt;/code&gt; subclass that maximizes the total area occupied by the &lt;code&gt;Panel&lt;/code&gt;'s children. Specifically, an arrangement without any empty cells will be preferred over one with an empty cell or two - even if the shape of the resulting items is less balanced. &lt;/p&gt;
&lt;img height="348" width="614" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/0844.BestFitPanel_2D00_Full.png" alt="MostFullPanel" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sometimes it's nice to optimize for the "shape" of individual items - and for that there's the &lt;code&gt;BestAnglePanel&lt;/code&gt; abstract base class which chooses the combination of &lt;em&gt;M&lt;/em&gt; and &lt;em&gt;N&lt;/em&gt; that yields items with a diagonal closest to some angle &lt;em&gt;A&lt;/em&gt; determined by the &lt;code&gt;GetIdealAngle&lt;/code&gt; override. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;MostSquarePanel&lt;/code&gt; is a &lt;code&gt;BestAnglePanel&lt;/code&gt; subclass that uses a value of 45&amp;deg; for &lt;em&gt;A&lt;/em&gt; and therefore prefers arrangements where items are closest to being square. &lt;/p&gt;
&lt;img height="348" width="614" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/6708.BestFitPanel_2D00_Square.png" alt="MostSquarePanel" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;MostGoldenPanel&lt;/code&gt;, on the other hand, is a &lt;code&gt;BestAnglePanel&lt;/code&gt; subclass that uses a value for &lt;em&gt;A&lt;/em&gt; that matches that of a horizontally-oriented &lt;a href="http://en.wikipedia.org/wiki/Golden_rectangle"&gt;golden rectangle&lt;/a&gt;. Golden rectangles are said to be among the most aesthetically pleasing shapes, and this class makes it easy to create layouts based around them. &lt;/p&gt;
&lt;img height="348" width="614" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/0028.BestFitPanel_2D00_Golden.png" alt="MostGoldenPanel" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Of course, there are very few values of &lt;em&gt;M&lt;/em&gt; and &lt;em&gt;N&lt;/em&gt; to choose from, so it's not uncommon that all the implementations above choose the &lt;strong&gt;same&lt;/strong&gt; values. The interesting differences tend to show up at various "special" sizes where each &lt;code&gt;BestFitPanel&lt;/code&gt; selects a &lt;em&gt;different&lt;/em&gt; layout. This is why the sample application allows you to enable all the panels at once: the sample content is translucent, so you can see where things differ and how each implementation is handling a particular configuration. I made sure all the arrangements above were unique - here's how it looks when they're all shown at once: &lt;/p&gt;
&lt;img height="348" width="614" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/6327.BestFitPanel_2D00_All.png" alt="All BestFitPanels overlapped" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For a real-world example of &lt;code&gt;BestFitPanel&lt;/code&gt; in action, I've adapted the "ImageLoading" sample from &lt;a href="http://blogs.msdn.com/b/delay/archive/2011/03/03/quot-your-feedback-is-important-to-us-please-stay-on-the-line-quot-improving-windows-phone-7-application-performance-is-even-easier-with-these-lowprofileimageloader-and-deferredloadlistbox-updates.aspx"&gt;my Windows Phone 7 PhonePerformance project&lt;/a&gt; to use &lt;code&gt;MostBigPanel&lt;/code&gt; (which is what I would have used if I'd written this post beforehand!). If you're not familiar with that sample, it finds all the followers of an arbitrary &lt;a href="https://twitter.com/"&gt;Twitter&lt;/a&gt; account and shows their images. Because it's impossible to know in advance how many followers an account has, trying to use one of the "in-box" &lt;code&gt;Panel&lt;/code&gt; implementations is likely to be tricky or require writing code to configure things at run-time. But &lt;code&gt;BestFitPanel&lt;/code&gt; makes this scenario &lt;strong&gt;easy&lt;/strong&gt; by automatically showing all the items &lt;em&gt;and&lt;/em&gt; optimizing for the most important attribute ("bigness" in this case). Here's the &lt;strong&gt;same&lt;/strong&gt; code/XAML with different numbers of followers (400, 200, and 100) to show how things "just work": &lt;/p&gt;
&lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/4846.BestFitPanel_2D00_400.jpg" alt="BestFitPanel with 400 items" /&gt; &lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/7673.BestFitPanel_2D00_200.jpg" alt="BestFitPanel with 200 items" /&gt; &lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/4034.BestFitPanel_2D00_100.jpg" alt="BestFitPanel with 100 items" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/BestFitPanel/BestFitPanel.zip"&gt;[Click here to download the complete source code for all the BestFitPanels along with sample projects for Silverlight, WPF, and Windows Phone 7.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The concept of a reusable, container-agnostic &lt;code&gt;Panel&lt;/code&gt; for layout is tremendously powerful. The "stock" implementations for Silverlight, WPF, and Windows Phone are all quite useful, but sometimes you'll find that writing a custom &lt;code&gt;Panel&lt;/code&gt; is the only way to get &lt;strong&gt;exactly&lt;/strong&gt; the layout you're looking for. Fortunately, layout code is pretty straightforward - and classes like &lt;code&gt;BestFitPanel&lt;/code&gt; and &lt;code&gt;BestAnglePanel&lt;/code&gt; make it even easier. So the next time you're looking for a flexible container that works sensibly &lt;em&gt;without&lt;/em&gt; requiring a bunch of prior knowledge or hand-holding, I hope you'll remember this post and consider using a &lt;code&gt;BestFitPanel&lt;/code&gt; - or a custom subclass! &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10147845" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/WPF/">WPF</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category></item><item><title>"Your feedback is important to us; please stay on the line..." [Improving Windows Phone 7 application performance is even easier with these LowProfileImageLoader and DeferredLoadListBox updates]</title><link>http://blogs.msdn.com/b/delay/archive/2011/03/03/quot-your-feedback-is-important-to-us-please-stay-on-the-line-quot-improving-windows-phone-7-application-performance-is-even-easier-with-these-lowprofileimageloader-and-deferredloadlistbox-updates.aspx</link><pubDate>Thu, 03 Mar 2011 17:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10136537</guid><dc:creator>David Anson</dc:creator><slash:comments>19</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10136537</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2011/03/03/quot-your-feedback-is-important-to-us-please-stay-on-the-line-quot-improving-windows-phone-7-application-performance-is-even-easier-with-these-lowprofileimageloader-and-deferredloadlistbox-updates.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;A few months ago &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/10/04/there-s-no-substitute-for-customer-feedback-improving-windows-phone-7-application-performance-now-a-bit-easier-with-lowprofileimageloader-and-deferredloadlistbox-updates.aspx"&gt;I began a similar post about LowProfileImageLoader/DeferredLoadListBox updates by saying&lt;/a&gt;: &lt;/p&gt;
&lt;blockquote&gt;Windows Phone 7 applications run on hardware that's considerably less powerful than what drives typical desktop and laptop machines. Therefore, tuning phone applications for optimum performance is an important task - and a challenging one! To help other developers, I previously coded and blogged about two classes: &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/02/keep-a-low-profile-lowprofileimageloader-helps-the-windows-phone-7-ui-thread-stay-responsive-by-loading-images-in-the-background.aspx"&gt;LowProfileImageLoader (pushes much of the cost of loading images off the UI thread)&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/08/never-do-today-what-you-can-put-off-till-tomorrow-deferredloadlistbox-and-stackpanel-help-windows-phone-7-lists-scroll-smoothly-and-consistently.aspx"&gt;DeferredLoadListBox (improves the scrolling experience for long lists)&lt;/a&gt;. These two classes can be used individually or together and have become a regular part of the recommendations for developers experiencing performance issues. &lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the time since, I've continued to hear from people who are benefitting from &lt;code&gt;LowProfileImageLoader&lt;/code&gt; and &lt;code&gt;DeferredLoadListBox&lt;/code&gt; - and the code has even been incorporated into the &lt;a href="http://wp7contrib.codeplex.com/"&gt;WP7Contrib project&lt;/a&gt;! Along the way, I've also collected some &lt;strong&gt;great&lt;/strong&gt; feedback, so I recently dedicated time to make a few improvements: &lt;/p&gt;
&lt;img height="554" width="305" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/6404.PhonePerformance_2D00_ListScrolling.png" alt="PhonePerformance List Scrolling sample" style="float:right" /&gt; 
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The most significant change is that I've removed the use of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.transformtovisual(VS.95).aspx"&gt;UIElement.TransformToVisual&lt;/a&gt; platform-level method from &lt;code&gt;DeferredLoadListBox&lt;/code&gt; because it has proven to be unreliable on Windows Phone 7 by throwing exceptions unexpectedly. Because this is &lt;strong&gt;not&lt;/strong&gt; the first time I've had to fix crashes due to random &lt;a href="http://msdn.microsoft.com/en-us/library/system.argumentexception(v=VS.95).aspx"&gt;ArgumentException&lt;/a&gt;s ("The parameter is incorrect."), &lt;span style="background-color:yellow"&gt;I recommend &lt;strong&gt;not&lt;/strong&gt; using the &lt;code&gt;TransformToVisual&lt;/code&gt; method in Windows Phone 7 applications until/unless the underlying problem is fixed&lt;/span&gt;. In the meantime, it has been my experience that the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.layoutinformation.getlayoutslot(v=VS.95).aspx"&gt;LayoutInformation.GetLayoutSlot&lt;/a&gt; method can often be used as a substitute with just a little bit of extra effort. &lt;/p&gt;
&lt;p&gt;I'd like to thank &lt;a href="http://mindre.net/"&gt;Tore Lervik&lt;/a&gt;, &lt;a href="http://developlabs.blogspot.com/"&gt;Baldelli Gabriele&lt;/a&gt;, and &lt;a href="http://www.glucosurfer.org/"&gt;Holger Schmeken&lt;/a&gt; for reporting this problem. &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: Another time I had to remove &lt;code&gt;TransformToVisual&lt;/code&gt; was for the &lt;a href="http://silverlight.codeplex.com/"&gt;Silverlight for Windows Phone Toolkit's&lt;/a&gt; &lt;code&gt;ContextMenu&lt;/code&gt; control. (This fix was part of the November 2010 release). &lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I've &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/08/never-do-today-what-you-can-put-off-till-tomorrow-deferredloadlistbox-and-stackpanel-help-windows-phone-7-lists-scroll-smoothly-and-consistently.aspx"&gt;previously explained why DeferredLoadListBox requires every container to have a height&lt;/a&gt; (note: each height can be different!). However, there are some scenarios where the Windows Phone 7 platform will report &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.actualheight(VS.95).aspx"&gt;ActualHeight&lt;/a&gt; to be 0 for a container even though its height has been explicitly and correctly set (ex: via &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox.itemcontainerstyle(VS.95).aspx"&gt;ItemContainerStyle&lt;/a&gt;). (Note: This seems to occur most often during scrolling.) Fortunately, I found an easy workaround that appears to resolve this problem in cases where the platform is misbehaving: a call to the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.updatelayout(VS.95).aspx"&gt;UpdateLayout&lt;/a&gt; API is sufficient to correct the value of &lt;code&gt;ActualHeight&lt;/code&gt;. &lt;/p&gt;
&lt;p&gt;I'd like to thank &lt;a href="http://blogs.xamlninja.com/"&gt;Rich Griffin&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/10/04/there-s-no-substitute-for-customer-feedback-improving-windows-phone-7-application-performance-now-a-bit-easier-with-lowprofileimageloader-and-deferredloadlistbox-updates.aspx#10119206"&gt;Michael James&lt;/a&gt; for reporting this problem. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;LowProfileImageLoader&lt;/code&gt; originally used a &lt;a href="http://msdn.microsoft.com/en-us/library/7977ey2c.aspx"&gt;Queue&lt;/a&gt; to implement &lt;a href="http://en.wikipedia.org/wiki/FIFO"&gt;"first in, first out" (FIFO)&lt;/a&gt; behavior of the image downloads it performs. This is a "fair" implementation and is ideal for slowly scrolling up/down a list that uses &lt;code&gt;LowProfileImageLoader&lt;/code&gt; and &lt;code&gt;DeferredLoadListBox&lt;/code&gt; together. However, for the scenario of &lt;em&gt;quickly&lt;/em&gt; scrolling such a list in a &lt;em&gt;single&lt;/em&gt; direction, FIFO behavior means the images you see on the screen will be among the &lt;strong&gt;last&lt;/strong&gt; to load. The "obvious" fix is to switch from a &lt;code&gt;Queue&lt;/code&gt; to a &lt;a href="http://msdn.microsoft.com/en-us/library/3278tedw.aspx"&gt;Stack&lt;/a&gt; which gives &lt;a href="http://en.wikipedia.org/wiki/LIFO_(computing)"&gt;"last in, first out (LIFO)&lt;/a&gt; behavior instead. But while that's better for the second scenario, it's worse for the first one - and it leads to a weird visual effect in apps like my &lt;code&gt;ImageLoading&lt;/code&gt; sample (part of the download) because the "wall" of images loads bottom-to-top instead of "top-to-bottom" as people expect. &lt;/p&gt;
&lt;p&gt;Clearly, there's no &lt;em&gt;perfect&lt;/em&gt; answer here, so the solution is to do well &lt;strong&gt;on average&lt;/strong&gt;! The classic way of amortizing unpredictable cost is to introduce randomness (ex: &lt;a href="http://en.wikipedia.org/wiki/Quicksort"&gt;the QuickSort algorithm&lt;/a&gt;) - so instead of processing FIFO or LIFO, &lt;code&gt;LowProfileImageLoader&lt;/code&gt; now works through its queue of pending work in random order. As a result, both the fast and the slow scrolling scenarios show images quickly and the application appears more responsive overall! &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: The way I've implemented randomization is a slight variation of the solution to a classic programming puzzle: &lt;em&gt;How do you sort a deck of &lt;strong&gt;N&lt;/strong&gt; cards in linear time and constant space?&lt;/em&gt; If you haven't seen this one before, take a minute to think about it before following &lt;a href="http://en.wikipedia.org/wiki/Knuth_shuffle"&gt;this link to a description of the Fisher-Yates/Knuth shuffle&lt;/a&gt;. &lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Though I initially meant for &lt;code&gt;LowProfileImageLoader&lt;/code&gt; and &lt;code&gt;DeferredLoadListBox&lt;/code&gt; to be used together, there's no reason &lt;code&gt;LowProfileImageLoader&lt;/code&gt; can't be used on its own. In fact, I previously ensured that it works fine when used with the default &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox(v=VS.95).aspx"&gt;ListBox&lt;/a&gt;/&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel(v=VS.95).aspx"&gt;VirtualizingStackPanel&lt;/a&gt; combination. However, when the user is scrolling such a list very quickly, the default container recycling behavior means there will be multiple &lt;a href="http://msdn.microsoft.com/en-us/library/cc278072(v=VS.95).aspx"&gt;data bindings&lt;/a&gt; applied to a particular container in rapid succession. Every one of these will enqueue a request for &lt;code&gt;LowProfileImageLoader&lt;/code&gt; to download the corresponding image - but &lt;strong&gt;only&lt;/strong&gt; the most recent one matters. Any previous requests are "stale" and although it's safe to satisfy them, it's also unnecessary. Therefore, I've made a change with this update to detect stale requests and discard them &lt;strong&gt;before&lt;/strong&gt; making an expensive web request on their behalf. This difference doesn't matter in non-virtualizing scenarios, but for virtualizing scenarios the amount of unnecessary work it saves can quickly add up! &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Another consequence of using &lt;code&gt;LowProfileImageLoader&lt;/code&gt; in the presence of container recycling is that re-used &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.image(VS.95).aspx"&gt;Image&lt;/a&gt; elements kept their old content until new content had been downloaded. This could lead to temporarily misleading UI where images show up alongside content they aren't associated with. It happens because &lt;code&gt;LowProfileImageLoader&lt;/code&gt; didn't previously "null-out" the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.image.source(v=VS.95).aspx"&gt;Source&lt;/a&gt; property when a new request was made. I've modified the code so it &lt;strong&gt;does&lt;/strong&gt; now - and the virtualizing experience is nicer because of it. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When implementing the worker thread logic for &lt;code&gt;LowProfileImageLoader&lt;/code&gt;, I intended for it to process &lt;code&gt;WorkItemQuantum&lt;/code&gt; number of items each time through the loop until the queue of requests was exhausted. I wrote the following code: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;for&lt;span style="color:#000000"&gt; (&lt;/span&gt;var&lt;span style="color:#000000"&gt; i = 0; (i &amp;lt; pendingRequests.Count) &amp;amp;&amp;amp; (i &amp;lt; WorkItemQuantum); i++)&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;I'd like to thank &lt;a href="http://ashterisk.wordpress.com/"&gt;Ashish Gupta&lt;/a&gt; for pointing out a bug here; what I meant was: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;for&lt;span style="color:#000000"&gt; (&lt;/span&gt;var&lt;span style="color:#000000"&gt; i = 0; (&lt;span style="background-color:yellow"&gt;0&lt;/span&gt; &amp;lt; pendingRequests.Count) &amp;amp;&amp;amp; (i &amp;lt; WorkItemQuantum); i++)&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Coding errors in loops can cause serious problems if they result in an attempt to process too many or too few items. I got lucky here because there's no &lt;em&gt;functional&lt;/em&gt; bug due to the original typo - the only downside is that &lt;em&gt;performance&lt;/em&gt; might be a little worse because it takes a couple of extra passes through the loop to complete once the count drops below &lt;code&gt;WorkItemQuantum&lt;/code&gt;. Fortunately, the value of &lt;code&gt;WorkItemQuantum&lt;/code&gt; is only 5, so the real-world impact of this is minimal. However, the whole point of this code is to help &lt;strong&gt;improve&lt;/strong&gt; performance, so I've fixed the oversight. &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;And finally, because &lt;a href="http://blogs.msdn.com/b/delay/archive/2011/02/24/candy-eating-lemming-delay-web-helpers-and-its-easy-to-use-amazon-s3-blob-bucket-api-is-now-available-via-nuget.aspx"&gt;I recently became a NuGet publishing "expert"&lt;/a&gt;, I've created a package for the &lt;code&gt;PhonePerformance&lt;/code&gt; assembly to make it easy to reference for all the NuGet fans out there. It contains the same binary you'd download below, but it contains &lt;strong&gt;only&lt;/strong&gt; the assembly (and its XML IntelliSense file) - the three sample projects are available only with the ZIP download. This split seems like a reasonable compromise to me: reference from the NuGet gallery if you know what you're doing and just need to add the binary to your project - &lt;strong&gt;or&lt;/strong&gt; - read the relevant blog posts and download the samples if you're getting started. &lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/PhonePerformance/PhonePerformance.zip"&gt;[Click here to download the compiled PhonePerformance assembly, sample applications, and full source code for everything.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;-OR-&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://www.nuget.org/List/Packages/PhonePerformance"&gt;[Click here to visit the NuGet gallery page for a package containing the PhonePerformance assembly.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Windows Phone 7 developers &lt;strong&gt;must&lt;/strong&gt; pay attention to performance because otherwise it's easy to end up with a slow, badly-behaved application. The &lt;code&gt;PhonePerformance&lt;/code&gt; assembly focuses on two common scenarios (image loading and list scrolling) and attempts to improve upon the default experience by making it easy to avoid known problem areas. As with any performance technique, results can vary &lt;em&gt;greatly&lt;/em&gt; depending on the specifics of each scenario, so it's important to take measurements and test everything on &lt;strong&gt;real&lt;/strong&gt; phone hardware. &lt;/p&gt;
&lt;p&gt;Many developers have told me they had success with the &lt;code&gt;PhonePerformance&lt;/code&gt; assembly - I hope you do, too! &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10136537" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category></item><item><title>sudo localize --crossplatform [Free PseudoLocalizer class makes it easy to identify localization issues in WPF, Silverlight, and Windows Phone 7 applications!]</title><link>http://blogs.msdn.com/b/delay/archive/2011/02/16/sudo-localize-crossplatform-free-pseudolocalizer-class-makes-it-easy-to-identify-localization-issues-in-wpf-silverlight-and-windows-phone-7-applications.aspx</link><pubDate>Wed, 16 Feb 2011 17:57:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10130509</guid><dc:creator>David Anson</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10130509</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2011/02/16/sudo-localize-crossplatform-free-pseudolocalizer-class-makes-it-easy-to-identify-localization-issues-in-wpf-silverlight-and-windows-phone-7-applications.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;Two posts ago, &lt;a href="http://blogs.msdn.com/b/delay/archive/2011/01/27/sudo-localize-amp-amp-make-me-a-sandwich-free-pseudolocalizer-class-makes-it-easy-for-anyone-to-identify-potential-localization-issues-in-net-applications.aspx"&gt;I explained the benefits of pseudo-localization and showed an easy way to implement it for WPF&lt;/a&gt; - then said I'd outline how to do the same for Silverlight and Windows Phone 7. In my previous post, &lt;a href="http://blogs.msdn.com/b/delay/archive/2011/02/07/what-it-lacks-in-efficiency-it-makes-up-for-in-efficiency-silverlight-ready-png-encoder-implementation-shows-one-way-to-use-net-ienumerables-effectively.aspx"&gt;I went off on the seeming diversion of implementing a PNG encoder for Silverlight&lt;/a&gt;. With this post, I'll fulfill my original promise &lt;strong&gt;and&lt;/strong&gt; unify the previous two posts! As you'll see, the basic principles of my approach to WPF localization translate fairly directly to Silverlight - though some limitations in the latter platform make achieving the same result more difficult. Even though more code and manual intervention are required for Silverlight and Windows Phone 7, the benefits are the same and pseudo-localization remains a &lt;strong&gt;great&lt;/strong&gt; way to identify potential problems early in the development cycle. &lt;/p&gt;
&lt;p&gt;For completeness I'll show examples and techniques for all platforms below... &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;img height="487" width="352" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/4135.PseudoLocalizer_2D00_Normal.jpg" alt="Normal WPF application" /&gt; &lt;img height="487" width="352" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/5125.PseudoLocalizer_2D00_Localized.jpg" alt="PseudoLocalizer in a WPF application" /&gt;
&lt;p style="font-size:8pt"&gt;&lt;em&gt;Please see the &lt;a href="http://blogs.msdn.com/b/delay/archive/2011/01/27/sudo-localize-amp-amp-make-me-a-sandwich-free-pseudolocalizer-class-makes-it-easy-for-anyone-to-identify-potential-localization-issues-in-net-applications.aspx"&gt;original post&lt;/a&gt; for an explanation of the changes shown above. &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Adding pseudo-localization of RESX resources to a WPF application&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Add the &lt;code&gt;PseudoLocalizer.cs&lt;/code&gt; file from the sample download to the project.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add &lt;code&gt;PSEUDOLOCALIZER_ENABLED&lt;/code&gt; to the (semi-colon-delimited) list of conditional compilation symbols for the project (via the &lt;strong&gt;Project&lt;/strong&gt; menu, &lt;strong&gt;Properties&lt;/strong&gt; item, &lt;strong&gt;Build&lt;/strong&gt; tab in Visual Studio).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add the following code somewhere it will be run soon after the application starts (for example, add a constructor for the &lt;code&gt;App&lt;/code&gt; class in &lt;code&gt;App.xaml.cs&lt;/code&gt;):&lt;/p&gt;
&lt;pre style="color:#000000"&gt;&lt;span style="color:#0000ff"&gt;#if&lt;/span&gt; PSEUDOLOCALIZER_ENABLED
    Delay.&lt;span style="color:#2b91af"&gt;PseudoLocalizer&lt;/span&gt;.Enable(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;em&gt;ProjectName&lt;/em&gt;.Properties.&lt;span style="color:#2b91af"&gt;Resources&lt;/span&gt;));
&lt;span style="color:#0000ff"&gt;#endif&lt;/span&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;If necessary&lt;/strong&gt;: Add a project reference to &lt;code&gt;System.Drawing&lt;/code&gt; (via &lt;strong&gt;Project&lt;/strong&gt; menu, &lt;strong&gt;Add Reference&lt;/strong&gt;, &lt;strong&gt;.NET&lt;/strong&gt; tab) if building the project now results in the error &lt;code&gt;"The type or namespace name 'Drawing' does not exist in the namespace 'System' (are you missing an assembly reference?)"&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;If necessary&lt;/strong&gt;: Right-click &lt;code&gt;Resources.resx&lt;/code&gt; and choose &lt;strong&gt;Run Custom Tool&lt;/strong&gt; if running the application under the debugger (F5) throws the exception &lt;code&gt;"No matching constructor found on type '&lt;em&gt;ProjectName&lt;/em&gt;.Properties.Resources'. You can use the Arguments or FactoryMethod directives to construct this type."&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Adding pseudo-localization of RESX resources to a Silverlight or Windows Phone 7 application&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Add the &lt;code&gt;PseudoLocalizer.cs&lt;/code&gt; and &lt;code&gt;PngEncoder.cs&lt;/code&gt; files from the sample download to the project.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add &lt;code&gt;PSEUDOLOCALIZER_ENABLED&lt;/code&gt; to the (semi-colon-delimited) list of conditional compilation symbols for the project (via the &lt;strong&gt;Project&lt;/strong&gt; menu, &lt;strong&gt;Properties&lt;/strong&gt; item, &lt;strong&gt;Build&lt;/strong&gt; tab in Visual Studio).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Make the following update to the auto-generated resource wrapper class by editing &lt;code&gt;Resources.Designer.cs&lt;/code&gt; directly (the highlighted portion is the primary change):&lt;/p&gt;
&lt;pre style="color:#000000"&gt;&lt;span style="color:#0000ff"&gt;#if&lt;/span&gt; PSEUDOLOCALIZER_ENABLED
    &lt;span style="color:#0000ff"&gt;global&lt;/span&gt;::System.Resources.&lt;span style="color:#2b91af"&gt;ResourceManager&lt;/span&gt; temp =
        &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="background-color:yellow"&gt;Delay.&lt;span style="color:#2b91af"&gt;PseudoLocalizerResourceManager&lt;/span&gt;&lt;/span&gt;(&lt;span style="color:#a31515"&gt;"PseudoLocalizerSL.Resources"&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;Resources&lt;/span&gt;).Assembly);
&lt;span style="color:#0000ff"&gt;#else&lt;/span&gt;&lt;span style="color:#808080"&gt;
    global::System.Resources.ResourceManager temp =
        new global::System.Resources.ResourceManager("PseudoLocalizerSL.Resources", typeof(Resources).Assembly);&lt;/span&gt;&lt;span style="color:#0000ff"&gt;
#endif&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;In case it's not clear, this change simply duplicates the existing line of code that creates an instance of &lt;a href="http://msdn.microsoft.com/en-us/library/system.resources.resourcemanager.aspx"&gt;ResourceManager&lt;/a&gt;, modifies it to create an instance of &lt;code&gt;Delay.PseudoLocalizerResourceManager&lt;/code&gt; instead, and wraps the two versions in an appropriate &lt;code&gt;#if&lt;/code&gt;/&lt;code&gt;#else&lt;/code&gt;/&lt;code&gt;#endif&lt;/code&gt; so pseudo-localization can be completely controlled by whether or not &lt;code&gt;PSEUDOLOCALIZER_ENABLED&lt;/code&gt; is &lt;code&gt;#define&lt;/code&gt;d. &lt;/p&gt;
&lt;blockquote&gt;&lt;strong style="color:red"&gt;Important&lt;/strong&gt;: This change will be &lt;strong&gt;silently overwritten&lt;/strong&gt; the next time (and &lt;em&gt;every&lt;/em&gt; time!) you make a change to &lt;code&gt;Resources.resx&lt;/code&gt; with the Visual Studio designer. Please see my notes below for more information on this Silverlight-/Windows Phone-specific gotcha. &lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;img height="577" width="355" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/0310.PseudoLocalizer_2D00_SL.png" alt="PseudoLocalizer in a Silverlight application" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Adding a pseudo-localizable string (all platforms)&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Double-click &lt;code&gt;Resources.resx&lt;/code&gt; to open the resource editor.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add the string by name and value.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Reference it from code/XAML.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Silverlight/Windows Phone 7&lt;/strong&gt;: Re-apply the &lt;code&gt;Delay.PseudoLocalizerResourceManager&lt;/code&gt; change to &lt;code&gt;Resources.Designer.cs&lt;/code&gt; which was silently undone when the new resource was added.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Adding a pseudo-localizable image (WPF only)&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Double-click &lt;code&gt;Resources.resx&lt;/code&gt; to open the resource editor.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click the "expand" arrow for &lt;strong&gt;Add Resource&lt;/strong&gt; and choose &lt;strong&gt;Add Existing File...&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Open the desired image file.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Reference it from code/XAML (possibly via &lt;code&gt;BitmapToImageSourceConverter.cs&lt;/code&gt; from the sample ZIP).&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Adding a pseudo-localizable image (all platforms)&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Rename the image file from &lt;code&gt;&lt;em&gt;Picture&lt;/em&gt;.jpg&lt;/code&gt; to &lt;code&gt;&lt;em&gt;Picture&lt;/em&gt;.jpg-bin&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Double-click &lt;code&gt;Resources.resx&lt;/code&gt; to open the resource editor.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click the "expand" arrow for &lt;strong&gt;Add Resource&lt;/strong&gt; and choose &lt;strong&gt;Add Existing File...&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Open the desired image file.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Reference it from code/XAML (probably via &lt;code&gt;ByteArrayToImageSourceConverter.cs&lt;/code&gt; from the sample ZIP).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Silverlight/Windows Phone 7&lt;/strong&gt;: Re-apply the &lt;code&gt;Delay.PseudoLocalizerResourceManager&lt;/code&gt; change to &lt;code&gt;Resources.Designer.cs&lt;/code&gt; which was silently undone when the new resource was added.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Optionally&lt;/strong&gt;: Restore the image's original file name in the &lt;code&gt;Resources&lt;/code&gt; folder of the project and manually update its file name in &lt;code&gt;Resources.resx&lt;/code&gt; using a text editor like &lt;a href="http://en.wikipedia.org/wiki/Notepad_(software)"&gt;Notepad&lt;/a&gt;. (I've done this for the sample project; it makes things a little clearer and it's easier to edit the image resource without having to rename it each time.) &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;img height="449" width="360" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/7585.PseudoLocalizer_2D00_WP7.png" alt="PseudoLocalizer in a Windows Phone 7 application" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There you have it - simple text &lt;strong&gt;and&lt;/strong&gt; image pseudo-localization for WPF, Silverlight, and Windows Phone 7 applications is within your grasp! &lt;nobr&gt;:)&lt;/nobr&gt; The basic concept is straightforward, though limitations make it a bit more challenging for Silverlight-based platforms. Nevertheless, the time you're likely to save by running &lt;code&gt;PseudoLocalizer&lt;/code&gt; early (and often) should &lt;strong&gt;far&lt;/strong&gt; outweigh any inconvenience along the way. By finding (and fixing) localization issues early, your application will be more friendly to customers - no matter what language they speak! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/PseudoLocalizer/PseudoLocalizer.zip"&gt;[Click here to download the complete source code for PseudoLocalizer, various helper classes, and the WPF, Silverlight, and Windows Phone 7 sample applications shown above.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Notes&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;For a brief overview of using RESX resources in a WPF, Silverlight, or Windows Phone 7 application, &lt;a href="http://blogs.msdn.com/b/delay/archive/2011/01/27/sudo-localize-amp-amp-make-me-a-sandwich-free-pseudolocalizer-class-makes-it-easy-for-anyone-to-identify-potential-localization-issues-in-net-applications.aspx"&gt;please see the "Notes" section of my original PseudoLocalizer post&lt;/a&gt;. You'll want to be sure the basic stuff is all hooked up and working correctly &lt;strong&gt;before&lt;/strong&gt; adding &lt;code&gt;PseudoLocalizer&lt;/code&gt; into the mix. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The act of using RESX-style resources in a Silverlight application is more difficult than it is in a WPF application (independent of pseudo-localization). WPF allows you to directly reference the generated resources class directly from XAML: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;Window.Resources&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;properties&lt;/span&gt;:&lt;span style="color:#a31515"&gt;Resources&lt;/span&gt;&lt;span style="color:#ff0000"&gt; x&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;Key&lt;/span&gt;="Resources"&lt;span style="color:#ff0000"&gt; xmlns&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;properties&lt;/span&gt;="clr-namespace:PseudoLocalizerWPF.Properties"/&amp;gt;
&amp;lt;/&lt;span style="color:#a31515"&gt;Window.Resources&lt;/span&gt;&amp;gt;
...
&amp;lt;&lt;span style="color:#a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Text&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;Binding&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Path&lt;/span&gt;=Message,&lt;span style="color:#ff0000"&gt; Source&lt;/span&gt;={&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Resources&lt;/span&gt;}}"/&amp;gt;&lt;/pre&gt;
&lt;p&gt;However, that approach doesn't work on Silverlight (or Windows Phone 7) because the generated constructor is &lt;a href="http://msdn.microsoft.com/en-us/library/7c5ka91b.aspx"&gt;internal&lt;/a&gt; and Silverlight's XAML parser refuses to create instances of such classes. Therefore, most people create a wrapper class (as &lt;a href="http://timheuer.com/blog/archive/2009/08/26/silverlight-string-localization.aspx"&gt;Tim Heuer explains here&lt;/a&gt;): &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&lt;span style="color:#808080"&gt;/// &amp;lt;summary&amp;gt;
///&lt;/span&gt;&lt;span style="color:#008000"&gt; Class that wraps the generated Resources class (for Resources.resx) in order to provide access from XAML on Silverlight.
&lt;/span&gt;&lt;span style="color:#808080"&gt;/// &amp;lt;/summary&amp;gt;
&lt;/span&gt;public class&lt;span style="color:#2b91af"&gt; ResourcesWrapper
&lt;/span&gt;&lt;span style="color:#000000"&gt;{
    &lt;/span&gt;private&lt;span style="color:#2b91af"&gt; Resources&lt;/span&gt;&lt;span style="color:#000000"&gt; _resources = &lt;/span&gt;new&lt;span style="color:#2b91af"&gt; Resources&lt;/span&gt;&lt;span style="color:#000000"&gt;();
    &lt;/span&gt;public&lt;span style="color:#2b91af"&gt; Resources&lt;/span&gt;&lt;span style="color:#000000"&gt; Resources
    {
        &lt;/span&gt;get&lt;span style="color:#000000"&gt; { &lt;/span&gt;return&lt;span style="color:#000000"&gt; _resources; }
    }
}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;And reference that instead: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;UserControl.Resources&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;local&lt;/span&gt;:&lt;span style="color:#a31515"&gt;Resources&lt;span style="background-color:yellow"&gt;Wrapper&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#ff0000"&gt; x&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;Key&lt;/span&gt;="Resources"&lt;span style="color:#ff0000"&gt; xmlns&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;local&lt;/span&gt;="clr-namespace:PseudoLocalizerSL"/&amp;gt;
&amp;lt;/&lt;span style="color:#a31515"&gt;UserControl.Resources&lt;/span&gt;&amp;gt;
...
&amp;lt;&lt;span style="color:#a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Text&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;Binding&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Path&lt;/span&gt;=&lt;span style="background-color:yellow"&gt;Resources.&lt;/span&gt;Message,&lt;span style="color:#ff0000"&gt; Source&lt;/span&gt;={&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Resources&lt;/span&gt;}}"/&amp;gt;&lt;/pre&gt;
&lt;p&gt;Obviously, the extra level of indirection adds overhead to every place resources are used in XAML - but that's a small price to pay for dodging the platform issue. &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;WPF supports &lt;a href="http://msdn.microsoft.com/en-us/library/f7ykdhsy.aspx"&gt;private reflection&lt;/a&gt; and &lt;code&gt;PseudoLocalizer&lt;/code&gt; takes advantage of that to enable a simple, seamless, "set it and forget it" hook-up (via the call to &lt;code&gt;Enable&lt;/code&gt; above). Unfortunately, private reflection isn't allowed on Silverlight, so the same trick doesn't work there. I considered a variety of different ways around this, and ultimately settled on editing the generated wrapper class code because it applies &lt;strong&gt;exactly&lt;/strong&gt; the same customization as on WPF. And while it's pretty annoying to have this tweak silently overwritten every time the RESX file is edited, it's simple enough to re-apply &lt;strong&gt;and&lt;/strong&gt; it's easy to spot when &lt;a href="http://en.wikipedia.org/wiki/Revision_control"&gt;reviewing changes&lt;/a&gt; before check-in. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I explained what's wrong with the default behavior of adding an image to a RESX file in my &lt;a href="http://blogs.msdn.com/b/delay/archive/2011/02/07/what-it-lacks-in-efficiency-it-makes-up-for-in-efficiency-silverlight-ready-png-encoder-implementation-shows-one-way-to-use-net-ienumerables-effectively.aspx"&gt;PngEncoder&lt;/a&gt; post: &lt;/p&gt;
&lt;blockquote&gt;[...] the technique I used for [WPF] (reading the &lt;a href="http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx"&gt;System.Drawing.Bitmap&lt;/a&gt; instance from the resources class and manipulating its pixels before handing it off to the application) won't work on Silverlight. You see, the &lt;code&gt;System.Drawing&lt;/code&gt; namespace/assembly doesn't exist for Silverlight! So although the RESX designer in Visual Studio will happily let you add an image to a Silverlight RESX file, actually &lt;em&gt;doing so&lt;/em&gt; results in an immediate compile error [...]. &lt;/blockquote&gt;
&lt;p&gt;Fortunately, the renaming trick I use above works well for Silverlight and Windows Phone - and WPF, too. So if you're looking to standardize on a single technique, &lt;strong&gt;this&lt;/strong&gt; is the one. &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;p&gt;Even if you're devoted to WPF and don't care about Silverlight, you should &lt;strong&gt;still&lt;/strong&gt; consider the &lt;code&gt;byte[]&lt;/code&gt; approach: although &lt;code&gt;System.Drawing.Bitmap&lt;/code&gt; is easier to deal with, it's not the right format. (Recall from the original &lt;code&gt;PseudoLocalizer&lt;/code&gt; post that I wrote an &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx"&gt;IValueConverter&lt;/a&gt; to convert from it to &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imagesource.aspx"&gt;System.Windows.Media.ImageSource&lt;/a&gt;.) Instead of loading images as &lt;code&gt;System.Drawing.Bitmap&lt;/code&gt; and converting them with &lt;code&gt;BitmapToImageSourceConverter&lt;/code&gt;, why not load them as &lt;code&gt;byte[]&lt;/code&gt; and convert them with &lt;code&gt;ByteArrayToImageSourceConverter.cs&lt;/code&gt; - and save a few CPU cycles by not bouncing through an unnecessary format? &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In addition to the renaming technique for accessing RESX images from Silverlight, there's a similar approach (courtesy of &lt;a href="http://forums.silverlight.net/forums/t/20368.aspx"&gt;Justin Van Patten&lt;/a&gt;) that renames to &lt;code&gt;.wav&lt;/code&gt; instead and exposes the resource as a &lt;a href="http://msdn.microsoft.com/en-us/library/system.io.stream.aspx"&gt;System.IO.Stream&lt;/a&gt;. For the purposes of pseudo-localization, the two renaming approaches &lt;em&gt;should&lt;/em&gt; be basically equivalent - which led me to go as far as hooking everything up and writing &lt;code&gt;StreamToImageSourceConverter.cs&lt;/code&gt; before I realized why the &lt;code&gt;Stream&lt;/code&gt; approach isn't viable... &lt;/p&gt;
&lt;p&gt;What it comes down to is an unfortunate API definition - the thing that's exposed by the wrapper class isn't a &lt;code&gt;Stream&lt;/code&gt;, it's an &lt;a href="http://msdn.microsoft.com/en-us/library/system.io.unmanagedmemorystream.aspx"&gt;UnmanagedMemoryStream&lt;/a&gt;! And while that would be perfectly fine as an implementation detail, it's &lt;strong&gt;not&lt;/strong&gt;: the type of the auto-generated property is &lt;code&gt;UnmanagedMemoryStream&lt;/code&gt; and the type returned by &lt;a href="http://msdn.microsoft.com/en-us/library/zxee5096.aspx"&gt;ResourceManager.GetStream&lt;/a&gt; is also &lt;code&gt;UnmanagedMemoryStream&lt;/code&gt;. But &lt;code&gt;UnmanagedMemoryStream&lt;/code&gt; can't be created by user code in Silverlight (and requires &lt;a href="http://msdn.microsoft.com/en-us/library/chfa2zb8.aspx"&gt;unsafe&lt;/a&gt; code in WPF), so this breaks &lt;code&gt;PseudoLocalizer&lt;/code&gt;'s approach of decoding/pseudo-localizing/re-encoding the image because it means the altered bytes can't be wrapped back up in a &lt;code&gt;UnmanagedMemoryStream&lt;/code&gt; to maintain the necessary pass-through behavior! &lt;/p&gt;
&lt;p&gt;If only the corresponding RESX interfaces had used the &lt;code&gt;Stream&lt;/code&gt; type (a base class of &lt;code&gt;UnmanagedMemoryStream&lt;/code&gt;), it would have been possible to wrap the altered image in a &lt;a href="http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx"&gt;MemoryStream&lt;/a&gt; and return that - a technique supported by all three platforms. Without digging into this &lt;strong&gt;too&lt;/strong&gt; much more, it seems to me that the &lt;code&gt;Stream&lt;/code&gt; type could have been used with no loss of generality - though perhaps there's a subtlety I'm missing. &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: As a general API design guideline, always seek to expose the most general type that makes sense for a particular scenario. That does &lt;strong&gt;not&lt;/strong&gt; mean everything should expose the &lt;a href="http://msdn.microsoft.com/en-us/library/system.object.aspx"&gt;Object&lt;/a&gt; type and cast everywhere - but it &lt;strong&gt;does&lt;/strong&gt; mean that (for example) APIs exposing a stream should use the &lt;code&gt;Stream&lt;/code&gt; type and thus &lt;em&gt;automatically&lt;/em&gt; work with &lt;code&gt;MemoryStream&lt;/code&gt;, &lt;code&gt;UnmanagedMemoryStream&lt;/code&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.sockets.networkstream.aspx"&gt;NetworkStream&lt;/a&gt;, etc.. Only when an API &lt;strong&gt;needs&lt;/strong&gt; something from a specific subclass should it use the more specific subclass. &lt;/blockquote&gt;
&lt;p&gt;Be that as it may, I didn't see a nice way of wrapping images in a &lt;code&gt;UnmanagedMemoryStream&lt;/code&gt;, and therefore recommend using the &lt;code&gt;byte[]&lt;/code&gt; approach instead! &lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10130509" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Technical/">Technical</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/WPF/">WPF</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category></item><item><title>What it lacks in efficiency, it makes up for in efficiency! [Silverlight-ready PNG encoder implementation shows one way to use .NET IEnumerables effectively]</title><link>http://blogs.msdn.com/b/delay/archive/2011/02/07/what-it-lacks-in-efficiency-it-makes-up-for-in-efficiency-silverlight-ready-png-encoder-implementation-shows-one-way-to-use-net-ienumerables-effectively.aspx</link><pubDate>Mon, 07 Feb 2011 18:01:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10125790</guid><dc:creator>David Anson</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10125790</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2011/02/07/what-it-lacks-in-efficiency-it-makes-up-for-in-efficiency-silverlight-ready-png-encoder-implementation-shows-one-way-to-use-net-ienumerables-effectively.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;At the end of &lt;a href="http://blogs.msdn.com/b/delay/archive/2011/01/27/sudo-localize-amp-amp-make-me-a-sandwich-free-pseudolocalizer-class-makes-it-easy-for-anyone-to-identify-potential-localization-issues-in-net-applications.aspx"&gt;my previous post about easily pseudo-localizing WPF applications&lt;/a&gt;, I said this post would show how to apply those concepts to a Silverlight application. Unfortunately, I seem to have made an &lt;a href="http://en.wikipedia.org/wiki/Off_by_one"&gt;off-by-one error&lt;/a&gt;: while this post is &lt;em&gt;related&lt;/em&gt; to that topic, it is &lt;strong&gt;not&lt;/strong&gt; the post I advertised. But it seems interesting in its own right, so I hope you enjoy it. &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;p&gt;Okay, so what does a &lt;a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics"&gt;PNG (Portable Network Graphics) image&lt;/a&gt; encoder have to do with pseudo-localizing on the Silverlight platform? Almost nothing - except for the fact that I went above and beyond with my last post and showed how to pseudo-localize not just text, but &lt;strong&gt;images&lt;/strong&gt; as well. It turns out the technique I used for that (reading the &lt;a href="http://msdn.microsoft.com/en-us/library/system.drawing.image.aspx"&gt;System.Drawing.Image&lt;/a&gt; instance from the resources class and manipulating its pixels before handing it off to the application) won't work on Silverlight. You see, the &lt;code&gt;System.Drawing&lt;/code&gt; namespace/assembly doesn't exist for Silverlight! So although the RESX designer in Visual Studio will happily let you add an image to a Silverlight RESX file, actually &lt;em&gt;doing so&lt;/em&gt; results in an immediate compile error: &lt;code&gt;The type or namespace name 'Drawing' does not exist in the namespace 'System' (are you missing an assembly reference?)&lt;/code&gt;... &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But all is not lost - &lt;a href="http://forums.silverlight.net/forums/t/20368.aspx"&gt;there are &lt;strong&gt;other&lt;/strong&gt; ways of adding an image to a RESX file&lt;/a&gt;! True, the process is a little wonky and cumbersome, but at least it works. However, the resulting resource is exposed as either a &lt;code&gt;byte[]&lt;/code&gt; or a &lt;a href="http://msdn.microsoft.com/en-us/library/system.io.stream.aspx"&gt;Stream&lt;/a&gt; instance - both of which are basically just a sequence of bytes. And because there's no &lt;a href="http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.setpixel.aspx"&gt;SetPixel&lt;/a&gt; method for byte arrays, this is a classic &lt;a href="http://en.wikipedia.org/wiki/Houston_we_have_a_problem#Popular_culture"&gt;"Houston, we have a problem"&lt;/a&gt; [sic; deliberately misquoting] moment for my original approach of pseudo-localizing the image by manipulating its pixels... Hum, &lt;a href="http://en.wikipedia.org/wiki/What%27s_a_Girl_to_Do%3F_(Bat_for_Lashes_song)"&gt;what's a girl to do?&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Well, those bytes &lt;em&gt;do&lt;/em&gt; correspond to an encoded image, so it ought to be possible to &lt;strong&gt;decode&lt;/strong&gt; the image - at which point we could wrap it in a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap(v=VS.95).aspx"&gt;WriteableBitmap&lt;/a&gt; and do the pixel manipulation via its &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.pixels(v=VS.95).aspx"&gt;Pixels&lt;/a&gt; property. After that, we could re-encode the altered pixels &lt;strong&gt;back&lt;/strong&gt; to an image file (remember that the resource data is expected to be the encoded bytes of an image) and things should work as seamlessly as they did for the original scenario. And they actually do! Well, on WPF, at least... &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;img height="225" width="300" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/4075.PngEncoder_2D00_Sample.png" alt="PngEncoder sample image" /&gt;
&lt;p style="font-size:8pt"&gt;&lt;em&gt;Sample PNG file encoded by PngEncoder&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Not on Silverlight, though. Silverlight will get you all the way to the last step, but that's the end of the line: the platform doesn't expose a way to do the re-encoding. &lt;nobr&gt;:(&lt;/nobr&gt; As you might guess, this is hardly the first time this issue has come up - a quick web search turns up &lt;strong&gt;plenty&lt;/strong&gt; of examples of people wanting to encode images under Silverlight. The typical recommendation is to find (or write) your own image encoder, and so there are a number of examples of Silverlight-compatible image encoders to be found! &lt;/p&gt;
&lt;p&gt;So &lt;strong&gt;why&lt;/strong&gt; did I write my own?? &lt;/p&gt;
&lt;p&gt;Well, because none of the examples I found was &lt;em&gt;quite&lt;/em&gt; what I wanted. The most obvious candidate just flat out didn't work; it crashed on every input I gave it. The runner-up (deliberately) took shortcuts for speed and didn't produce valid output. The third option was released under a license I'm not able to work with. And the fourth was part of a much larger image encoding library I didn't feel like pulling apart. Besides, I release full source code on my blog, and I don't want to be in the business of distributing other peoples' code with my samples. A lot of times it's just easier and safer to code something myself - and I've had a lot of great learning experiences as a result! &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When choosing an image format for re-encoding on the fly, Silverlight makes the decision fairly easy because it supports only two image formats: &lt;a href="http://en.wikipedia.org/wiki/Jpeg"&gt;JPEG&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics"&gt;PNG&lt;/a&gt;. Because JPEG is a lossy format, it's pretty much a non-starter (we don't want to degrade image quality) and therefore lossless PNG is the obvious choice. Conveniently, the PNG image format is fairly simple - especially if you're willing to punt on (losslessly) compressing the image! All you need to encode a PNG file is a format prefix (8 bytes), a header chunk (5 bytes), an image chunk with the properly encoded pixels, and an end chunk (0 bytes). There's a decent amount of bookkeeping to be done along the way (scanline filtering, compression block creation, two different &lt;a href="http://en.wikipedia.org/wiki/Hash_algorithm"&gt;hash algorithms&lt;/a&gt;, etc.), but it's all fairly straightforward. And the &lt;a href="http://www.w3.org/TR/PNG/"&gt;PNG specification&lt;/a&gt; is well-written and fairly easy to follow - what more could you ask for? &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: Giving up on compression may seem like a big deal, but I don't think it is for the scenario at hand. While small file size is important for making the best use of long-term storage, the pseudo-localization scenario creates its PNG file on the fly, loads it, and &lt;strong&gt;immediately&lt;/strong&gt; discards it. The encoded image simply isn't around for very long and so its large size shouldn't matter. &lt;/blockquote&gt;
&lt;p&gt;Okay, so PNG encoding isn't rocket science - but I still feel that if I'm going to &lt;a href="http://en.wikipedia.org/wiki/Reinventing_the_wheel"&gt;reinvent the wheel&lt;/a&gt;, then at least I should try to contribute &lt;em&gt;something&lt;/em&gt; new or interesting to the mix! &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What I've done here is to use &lt;a href="http://msdn.microsoft.com/en-us/library/9eekhta0.aspx"&gt;IEnumerable&lt;/a&gt; everywhere: &lt;/p&gt;
&lt;pre style="color:#000000"&gt;&lt;span style="color:#0000ff"&gt;namespace&lt;/span&gt; Delay
{
    &lt;span style="color:#808080"&gt;/// &amp;lt;summary&amp;gt;
    ///&lt;/span&gt;&lt;span style="color:#008000"&gt; Class that encodes a sequence of pixels to a sequence of bytes representing a PNG file (uncompressed).
&lt;/span&gt;&lt;span style="color:#808080"&gt;    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;remarks&amp;gt;
    ///&lt;/span&gt;&lt;span style="color:#008000"&gt; Reference: http://www.w3.org/TR/PNG/.
&lt;/span&gt;&lt;span style="color:#808080"&gt;    /// &amp;lt;/remarks&amp;gt;
&lt;/span&gt;&lt;span style="color:#0000ff"&gt;    static class&lt;/span&gt;&lt;span style="color:#2b91af"&gt; PngEncoder
&lt;/span&gt;    {
        &lt;span style="color:#808080"&gt;/// &amp;lt;summary&amp;gt;
        ///&lt;/span&gt;&lt;span style="color:#008000"&gt; Encodes the specified pixels to a sequence of bytes representing a PNG file.
&lt;/span&gt;&lt;span style="color:#808080"&gt;        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="width"&amp;gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;Width of the image.&lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="height"&amp;gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;Height of the image.&lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="pixels"&amp;gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;Pixels of the image in ARGB format.&lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color:#008000"&gt;Sequence of bytes representing a PNG file.&lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;/returns&amp;gt;
&lt;/span&gt;&lt;span style="color:#0000ff"&gt;        public static&lt;/span&gt;&lt;span style="color:#2b91af"&gt; IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;byte&lt;/span&gt;&amp;gt; Encode(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; width, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; height, &lt;span style="color:#2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;&amp;gt; pixels) { &lt;span style="color:#008000"&gt;/* ... */&lt;/span&gt; }
    }
}&lt;/pre&gt;
&lt;p&gt;And &lt;code&gt;IEnumerable&lt;/code&gt; isn't just for the public API, it's used throughout the code, too! This is the meaning behind the title of this post: giving up on compression is &lt;strong&gt;in&lt;/strong&gt;efficient from a storage space perspective, but operating exclusively on enumerations is very &lt;strong&gt;e&lt;/strong&gt;fficient from a memory consumption and a computational efficiency perspective! Because of that, this class can encode a 20-megabyte PNG file &lt;strong&gt;without&lt;/strong&gt; allocating any more memory than it takes to encode a 1-byte PNG file. What's more, &lt;strong&gt;no&lt;/strong&gt; work is done before it needs to be: if you're streaming a PNG file across a slow transport, the file will be read and encoded only as quickly as the receiver consumes the bytes - and if encoding is aborted mid-way for some reason, no unnecessary effort has been wasted! &lt;/p&gt;
&lt;p&gt;This efficiency is possible thanks to the way &lt;code&gt;IEnumerable&lt;/code&gt; works and the convenience of C#'s &lt;a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"&gt;yield return&lt;/a&gt; which makes it easy to write code that returns an &lt;code&gt;IEnumerable&lt;/code&gt; without explicitly implementing &lt;a href="http://msdn.microsoft.com/en-us/library/78dfe2yb.aspx"&gt;IEnumerator&lt;/a&gt;. As a result, the code for &lt;code&gt;PngEncoder&lt;/code&gt; is clear and linear with no hint (or visible complexity) of the allocation savings or deferred processing that occur under the covers. Instead, everything communicates in terms of byte sequences - translating one sequence to another inline as necessary. For example, every horizontal line of an encoded PNG image is prefixed with a byte indicating which filtering algorithm was used. These filter bytes aren't part of the original pixels that are passed into the &lt;code&gt;Encode&lt;/code&gt; call, so they need to be added. What's cool is that it's easy to write a method to do so - and because it takes an &lt;code&gt;IEnumerable&lt;/code&gt; input parameter and returns an &lt;code&gt;IEnumerable&lt;/code&gt; result, such a method can be trivially "injected" into &lt;strong&gt;any&lt;/strong&gt; data flow! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;One particularly handy realization of this technique is demonstrated by a class I called &lt;code&gt;WrappedEnumerable&lt;/code&gt; - here's what it looks like to the developer: &lt;/p&gt;
&lt;pre style="color:#808080"&gt;/// &amp;lt;summary&amp;gt;
///&lt;span style="color:#008000"&gt; Class that wraps an IEnumerable(T) or IEnumerator(T) in order to do something with each byte as it is enumerated.
&lt;/span&gt;/// &amp;lt;/summary&amp;gt;
/// &amp;lt;typeparam name="T"&amp;gt;&lt;span style="color:#008000"&gt;Type of element being enumerated.&lt;/span&gt;&amp;lt;/typeparam&amp;gt;
&lt;span style="color:#0000ff"&gt;abstract class&lt;/span&gt;&lt;span style="color:#2b91af"&gt; WrappedEnumerable&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;lt;T&amp;gt; : &lt;span style="color:#2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;T&amp;gt;, &lt;span style="color:#2b91af"&gt;IEnumerator&lt;/span&gt;&amp;lt;T&amp;gt;
{
    &lt;/span&gt;/// &amp;lt;summary&amp;gt;
    ///&lt;span style="color:#008000"&gt; Method called to initialize for a new (or reset) enumeration.
&lt;/span&gt;    /// &amp;lt;/summary&amp;gt;
&lt;span style="color:#0000ff"&gt;    protected virtual void&lt;/span&gt;&lt;span style="color:#000000"&gt; Initialize() { }

    &lt;/span&gt;/// &amp;lt;summary&amp;gt;
    ///&lt;span style="color:#008000"&gt; Method called for each byte output by the underlying enumerator.
&lt;/span&gt;    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name="value"&amp;gt;&lt;span style="color:#008000"&gt;Next value.&lt;/span&gt;&amp;lt;/param&amp;gt;
&lt;span style="color:#0000ff"&gt;    protected abstract void&lt;/span&gt;&lt;span style="color:#000000"&gt; OnValueEnumerated(T value);
}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;WrappedEnumerable&lt;/code&gt; is useful for &lt;code&gt;PngEncoder&lt;/code&gt; because the encoding process makes use of two different hash algorithms: &lt;a href="http://en.wikipedia.org/wiki/CRC-32"&gt;CRC-32&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Adler-32"&gt;Adler-32&lt;/a&gt;. Long-time readers of this blog know I'm no stranger to hash functions - in fact, &lt;a href="http://blogs.msdn.com/b/delay/archive/2009/01/14/free-hash-a-reusable-crc-32-hashalgorithm-implementation-for-net.aspx"&gt;I've previously shared code to implement CRC-32 based on the very same PNG specification&lt;/a&gt;! But as much as I love .NET's &lt;a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.aspx"&gt;HashAlgorithm&lt;/a&gt;, using it here seemed like it might be overkill. &lt;code&gt;HashAlgorithm&lt;/code&gt; is ideal for processing large chunks of data at a time, but the sequence-oriented nature of &lt;code&gt;PngEncoder&lt;/code&gt; deals with a single byte at a time. So what I did was to create &lt;code&gt;WrappedEnumerable&lt;/code&gt; subclasses &lt;code&gt;Crc32WrappedEnumerable&lt;/code&gt; and &lt;code&gt;Adler32WrappedEnumerable&lt;/code&gt; which override the two methods above to calculate their hash values &lt;em&gt;as the bytes flow through the system&lt;/em&gt;! These are both simple classes and work quite well for "injecting" hash math into a data flow. The PNG format puts stores its hash values &lt;strong&gt;after&lt;/strong&gt; the corresponding data, so by the time that value is needed, the relevant data has already flowed through the &lt;code&gt;WrappedEnumerable&lt;/code&gt; and the final hash is ready to be retrieved. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;However, the same cannot be said of the length fields in the PNG specification... Lengths are stored &lt;strong&gt;before&lt;/strong&gt; the corresponding data, and that poses a distinct problem when you're trying to avoid looking ahead: without knowing what data is coming, it's hard to know how much there is! But I'm able to cheat here: because &lt;code&gt;PngEncoder&lt;/code&gt; doesn't compress, it turns out that &lt;strong&gt;all&lt;/strong&gt; the internal lengths can be calculated from the original &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; values passed to the call to &lt;code&gt;Encode&lt;/code&gt;! So while this is a &lt;em&gt;bit&lt;/em&gt; algorithmically impure, it completely sidesteps the length issue and avoids the need to buffer up arbitrarily long sequences of data just to know how long they are. &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: After spending so much time celebrating the &lt;code&gt;IEnumerable&lt;/code&gt; way of life, this is probably a good time to highlight one of its subtle risks: multiple enumeration due to deferred execution. Multiple enumeration is something that comes up a lot in the context of &lt;a href="http://msdn.microsoft.com/library/bb397926.aspx"&gt;LINQ&lt;/a&gt; - an &lt;code&gt;IEnumerable&amp;lt;byte&amp;gt;&lt;/code&gt; is &lt;strong&gt;not&lt;/strong&gt; the same thing as a &lt;code&gt;byte[]&lt;/code&gt;. Whereas it's perfectly reasonable to pass a &lt;code&gt;byte[]&lt;/code&gt; off to two different functions to deal with, doing the same thing with an &lt;code&gt;IEnumerable&amp;lt;byte&amp;gt;&lt;/code&gt; usually results in that sequence being created and enumerated twice! Depending on where the sequence comes from, this can range from inefficient (a duplication of effort) to catastrophic (it may not be &lt;strong&gt;possible&lt;/strong&gt; to generate the sequence a second time). The topic of multiple enumeration is rich enough to merit its own blog post (&lt;a href="http://weblogs.asp.net/okloeten/archive/2008/05/27/6225197.aspx"&gt;here's one&lt;/a&gt; and &lt;a href="http://www.hookedonlinq.com/DeferredExecution.ashx"&gt;here's another&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/csharpfaq/archive/2009/01/26/does-the-linq-to-objects-provider-have-built-in-performance-optimization.aspx"&gt;here's another&lt;/a&gt;), and I won't go into it further here. But be on the look-out, because it can be tricky! &lt;/blockquote&gt;
&lt;blockquote&gt;&lt;strong&gt;Further aside&lt;/strong&gt;: To help avoid this problem in &lt;code&gt;PngEncoder&lt;/code&gt;, I created the &lt;code&gt;TrackingEnumerable&lt;/code&gt; and &lt;code&gt;TrackingEnumerator&lt;/code&gt; classes in the sample project. These are simple &lt;code&gt;IEnumerable&lt;/code&gt;/&lt;code&gt;IEnumerator&lt;/code&gt; implementations except that they output a string with &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.debug.writeline.aspx"&gt;Debug.WriteLine&lt;/a&gt; whenever a new enumeration is begun. For the purposes of &lt;code&gt;PngEncoder&lt;/code&gt;, seeing any more than &lt;strong&gt;one&lt;/strong&gt; of these outputs represents a bug! &lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In an attempt to ensure that my &lt;code&gt;PngEncoder&lt;/code&gt; implementation behaves well and produces valid PNG files, I've written a small collection of automated tests (included with the download). Most of them are concerned with parameter validation and correct behavior with regard to the &lt;code&gt;IEnumerable&lt;/code&gt; idiosyncrasies I mentioned earlier, but the one called "RandomImages" is all about output verification. That test creates 25 PNG files of random size and contents, encodes them with &lt;code&gt;PngEncoder&lt;/code&gt;, then decodes them with two &lt;strong&gt;different&lt;/strong&gt; decoder implementations (&lt;a href="http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx"&gt;System.Drawing.Bitmap&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.pngbitmapdecoder.aspx"&gt;System.Windows.Media.Imaging.PngBitmapDecoder&lt;/a&gt;) and verifies the output is identical to the input. I've also verified that &lt;code&gt;PngEncoder&lt;/code&gt;'s PNG files can be opened in a variety of different image viewing/editing applications. (Interesting tidbit: Internet Explorer seems to be the strictest about requiring valid PNG files!) While none of this is a &lt;strong&gt;guarantee&lt;/strong&gt; that all images will encode successfully, I'm optimistic typical scenarios will work well for people. &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/PngEncoder/PngEncoder.zip"&gt;[Click here to download the source code for the complete PngEncoder.cs implementation, a simple test application, and the automated test suite.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;At the end of the day, the big question is whether my focus (obsession?) with an &lt;code&gt;IEnumerable&lt;/code&gt;-centric implementation was justified. From a practical point of view, you could argue this either way - I happen to think things worked out pretty elegantly, but others might argue the code would be clearer with explicit allocations. I'll claim the memory/computational benefits I describe here are pretty compelling (especially in resource-constrained scenarios like Windows Phone), but others could reasonably argue that na&amp;iuml;ve consumers of &lt;code&gt;PngEncoder&lt;/code&gt; are likely to write their code in a way that negates those benefits (ex: by calling &lt;a href="http://msdn.microsoft.com/en-us/library/bb298736.aspx"&gt;ToArray&lt;/a&gt;). &lt;/p&gt;
&lt;p&gt;However, I'm not going to spend a lot of time second-guessing myself; I think it was a great experience. &lt;nobr&gt;:)&lt;/nobr&gt; The following sums up my thoughts on the matter pretty nicely: &lt;/p&gt;
&lt;blockquote&gt;&lt;em&gt;The road of life twists and turns and no two directions are ever the same. Yet our lessons come from the journey, not the destination.&lt;/em&gt; - &lt;a href="http://thinkexist.com/quotation/the-road-of-life-twists-and-turns-and-no-two/763577.html"&gt;Don Williams, Jr.&lt;/a&gt; &lt;/blockquote&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10125790" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Technical/">Technical</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/WPF/">WPF</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category></item><item><title>sudo localize &amp; make me-a-sandwich [Free PseudoLocalizer class makes it easy for anyone to identify potential localization issues in .NET applications]</title><link>http://blogs.msdn.com/b/delay/archive/2011/01/27/sudo-localize-amp-amp-make-me-a-sandwich-free-pseudolocalizer-class-makes-it-easy-for-anyone-to-identify-potential-localization-issues-in-net-applications.aspx</link><pubDate>Thu, 27 Jan 2011 18:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10121146</guid><dc:creator>David Anson</dc:creator><slash:comments>8</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10121146</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2011/01/27/sudo-localize-amp-amp-make-me-a-sandwich-free-pseudolocalizer-class-makes-it-easy-for-anyone-to-identify-potential-localization-issues-in-net-applications.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;I've previously &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/12/20/quot-and-she-d-say-can-you-see-what-i-m-saying-quot-how-to-localize-a-windows-phone-7-application-that-uses-the-windows-phone-toolkit-into-different-languages.aspx"&gt;written about the benefits of localization and shown how to localize Windows Phone 7 applications&lt;/a&gt;. The techniques I describe in that post constitute a good workflow that's just as suitable for WPF and Silverlight desktop applications! But even with good processes in place, the way localization is done in the real world has some challenges... &lt;/p&gt;
&lt;p&gt;You see, localization can be &lt;strong&gt;expensive&lt;/strong&gt;: hiring people to translate an entire application, re-testing it in the newly supported locale, fixing resulting bugs, etc.. So teams often wait till near the end of the release cycle - after the UI has stabilized - to start localizing the application. This is a perfectly reasonable approach, but there are invariably a few surprises - usually some variation of "&lt;em&gt;What do you mean that string is hard-coded in English and can't be translated??&lt;/em&gt;". It sure would be nice if teams could do some kind of low-cost localization in order to identify - and fix - oversights like this long before they turn into problems... &lt;/p&gt;
&lt;p&gt;Yep - that process is known as &lt;a href="http://en.wikipedia.org/wiki/Pseudo_localization"&gt;pseudo-localization&lt;/a&gt;. What pseudo-localization does is create alternate versions of resource strings by using different characters that &lt;strong&gt;look&lt;/strong&gt; similar enough to the original English characters that text is still readable - but obviously "localized". (This is one of those "&lt;a href="http://en.wikipedia.org/wiki/A_picture_is_worth_a_thousand_words"&gt;a picture is worth a thousand words&lt;/a&gt;" moments, so please check out the &lt;a href="http://en.wikipedia.org/wiki/Pseudo_localization"&gt;Wikipedia article&lt;/a&gt; or bear with me for just a moment...) Additionally, because some languages tend to have longer phrases than English (&lt;em&gt;German, I'm looking at you!&lt;/em&gt;), there's often an additional aspect of string lengthening to simulate that and help detect wrapping, clipping, and the like. &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: It's important to remember that the character "translations" are chosen exclusively on the basis of how similar they look to the original character and &lt;strong&gt;not&lt;/strong&gt; on the basis of linguistic correctness, cultural influence, or anything like that! &lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here's the sample application I created for this post running in its normal English mode. (It's not very sophisticated, but it's good enough for our purposes.) &lt;em&gt;Can you tell if all the strings are properly localizable? Are there any other localization concerns here?&lt;/em&gt; &lt;/p&gt;
&lt;img height="487" width="352" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/4135.PseudoLocalizer_2D00_Normal.jpg" alt="Normal application" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Pseudo-localization isn't a new concept and there are a variety of tools out there that do a fine job of it. However, none of the ones I found during a quick search appeared to be free, simple to use, and unencumbered by restrictions (i.e., licensing, distribution, etc.). So I thought it would be fun to write my own and share it with the community as open source under the &lt;a href="http://opensource.org/licenses/ms-pl.html"&gt;very permissive Ms-PL license&lt;/a&gt;. &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;p&gt;The class I've created is called &lt;code&gt;PseudoLocalizer&lt;/code&gt; and it automatically pseudo-localizes standard .NET &lt;a href="http://msdn.microsoft.com/en-us/library/ekyft91f.aspx"&gt;RESX&lt;/a&gt;-based resources. Using RESX-based resources is the &lt;a href="http://msdn.microsoft.com/en-us/library/ff637520(VS.92).aspx"&gt;recommend approach for building localizable Silverlight and Windows Phone 7 applications&lt;/a&gt;, the &lt;a href="http://msdn.microsoft.com/en-us/library/y99d1cd3.aspx"&gt;recommended approach for building localizable Windows Forms applications&lt;/a&gt;, and also a perfectly fine approach for building localizable WPF applications. &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: The &lt;em&gt;recommended&lt;/em&gt; technique for localizing WPF applications is actually &lt;a href="http://msdn.microsoft.com/en-us/library/ms788718.aspx"&gt;something else&lt;/a&gt;, but I have some issues with that approach and won't be discussing it here. &lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I've said it's easy to use &lt;code&gt;PseudoLocalizer&lt;/code&gt;: all it takes are &lt;a href="http://en.wikipedia.org/wiki/Special_Agent_Oso"&gt;three special steps&lt;/a&gt;: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Add the (self-contained) &lt;code&gt;PseudoLocalizer.cs&lt;/code&gt; file from the sample download to your project.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add the following code somewhere it will be run once and run early (ex: the application's constructor):&lt;/p&gt;
&lt;pre style="color:#000000"&gt;&lt;span style="color:#0000ff"&gt;#if&lt;/span&gt; PSEUDOLOCALIZER_ENABLED
    Delay.&lt;span style="color:#2b91af"&gt;PseudoLocalizer&lt;/span&gt;.Enable(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;em&gt;ProjectName&lt;/em&gt;.Properties.&lt;span style="color:#2b91af"&gt;Resources&lt;/span&gt;));
&lt;span style="color:#0000ff"&gt;#endif&lt;/span&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add &lt;code&gt;PSEUDOLOCALIZER_ENABLED&lt;/code&gt; to the list of conditional compilation symbols for your project (via the &lt;strong&gt;Project&lt;/strong&gt; menu, &lt;strong&gt;Properties&lt;/strong&gt; item, &lt;strong&gt;Build&lt;/strong&gt; tab in Visual Studio).&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Done! Not only will all localizable strings be automatically pseudo-localized, but &lt;strong&gt;images&lt;/strong&gt; will, too! How does one pseudo-localize an image?? Well, I considered a variety of techniques, but settled on simply inverting the colors to create a &lt;a href="http://en.wikipedia.org/wiki/Negative_(photography)"&gt;negative image&lt;/a&gt;. This has the nice benefit of keeping the image dimensions the same (which is sometimes important) as well as preserving any directional aspects it might have (i.e., an image of an arrow pointing left has the same meaning after being "localized"). &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: I've never seen image pseudo-localization before, but it seems like the obvious next step. Although many images don't need to be localized (ex: a gradient background), some images have text in them or make assumptions that aren't true in all locales (ex: &lt;a href="http://en.wikipedia.org/wiki/Thumbs_up"&gt;thumbs up&lt;/a&gt; means "good"). So it seems pretty handy to know which images aren't localizable! &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Okay, let's see how well you did on the localization quiz! Here's the sample application with &lt;code&gt;PseudoLocalizer&lt;/code&gt; enabled: &lt;/p&gt;
&lt;img height="487" width="352" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/5125.PseudoLocalizer_2D00_Localized.jpg" alt="Pseudo-localized application" /&gt;
&lt;p&gt;Hum... While it's clear &lt;strong&gt;most&lt;/strong&gt; of the text was correctly localizable (and therefore automatically pseudo-localized), it appears the lazy developer (&lt;em&gt;uh, wait, that's me...&lt;/em&gt;) forgot to put one of the strings in the RESX file: "Goodbye" is hardcoded to English in the XAML. &lt;nobr&gt;:(&lt;/nobr&gt; Fortunately, the image &lt;strong&gt;is&lt;/strong&gt; localizable, so it can be changed if necessary. &lt;strong&gt;Un&lt;/strong&gt;fortunately, the fixed-width application window seems to be a little too narrow for longer translations (like German) and is clipping two of the pseudo-localized strings! Nuts, I'm afraid this application may need a bit more work before we can feel good about our ability to ship versions for other languages... &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/PseudoLocalizer/PseudoLocalizer.zip"&gt;[Click here to download the complete source code the PseudoLocalizer and the WPF sample application shown above.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Notes:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;What I've described in this post works &lt;span style="background-color:yellow"&gt;only on WPF&lt;/span&gt;; Silverlight has a couple of limitations that prevent what I've done from working exactly as-is. My &lt;strong&gt;next&lt;/strong&gt; blog post will discuss how to overcome those limitations and use &lt;code&gt;PseudoLocalizer&lt;/code&gt; on Silverlight, too! &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The way &lt;code&gt;PseudoLocalizer&lt;/code&gt; works so seamlessly is by examining the type of the generated resource class and using (private) &lt;a href="http://msdn.microsoft.com/en-us/library/f7ykdhsy.aspx"&gt;reflection&lt;/a&gt; to swap in a custom &lt;a href="http://msdn.microsoft.com/en-us/library/system.resources.resourcemanager.aspx"&gt;ResourceManager&lt;/a&gt; class for the default one. This &lt;code&gt;PseudoLocalizerResourceManager&lt;/code&gt; works the same as the default one for loading resources - then it post-processes strings and bitmaps to provide its pseudo-localization effects. Private reflection (i.e., examining and/or modifying the internal data of an object) is generally a &lt;strong&gt;bad&lt;/strong&gt; practice - but I tend to believe it's acceptable here because the target class is simple, its (generated) code is part of the project, and &lt;code&gt;PseudoLocalizer&lt;/code&gt; is only ever going to be used as a development tool (i.e., never in a released application). &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For readers who want a brief overview of how to use RESX-resources in WPF, here you go: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Set the Access Modifier to "Public" in the RESX designer so the auto-generated resource property accessors will be accessible to the WPF data-binding system. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create an instance of the auto-generated RESX class (typically named "Resources") as a WPF-accessible resource: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;Window.Resources&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;properties&lt;/span&gt;:&lt;span style="color:#a31515"&gt;Resources&lt;/span&gt;&lt;span style="color:#ff0000"&gt; x&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;Key&lt;/span&gt;="Resources"&lt;span style="color:#ff0000"&gt; xmlns&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;properties&lt;/span&gt;="clr-namespace:PseudoLocalizerWPF.Properties"/&amp;gt;
&amp;lt;/&lt;span style="color:#a31515"&gt;Window.Resources&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a &lt;a href="http://msdn.microsoft.com/en-us/library/ms750413.aspx"&gt;Binding&lt;/a&gt; that references the relevant properties of that resource wherever you want to use them: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Text&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;Binding&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Path&lt;/span&gt;=AlphabetLower,&lt;span style="color:#ff0000"&gt; Source&lt;/span&gt;={&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Resources&lt;/span&gt;}}"/&amp;gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Because RESX files expose images as instances of &lt;a href="http://msdn.microsoft.com/en-us/library/system.drawing.image.aspx"&gt;System.Drawing.Image&lt;/a&gt; and WPF deals with &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imagesource.aspx"&gt;System.Windows.Media.ImageSource&lt;/a&gt;, I wrote a simple &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx"&gt;IValueConverter&lt;/a&gt; to convert from the former to the latter. (And it's part of the source code download.) Using &lt;code&gt;BitmapToImageSourceConverter&lt;/code&gt; follows the usual pattern for value converters: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create an instance as a resource: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;delay&lt;/span&gt;:&lt;span style="color:#a31515"&gt;BitmapToImageSourceConverter&lt;/span&gt;&lt;span style="color:#ff0000"&gt; x&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;Key&lt;/span&gt;="BitmapToImageSourceConverter"&lt;span style="color:#ff0000"&gt; xmlns&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;delay&lt;/span&gt;="clr-namespace:Delay"/&amp;gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use that resource in the relevant &lt;code&gt;Binding&lt;/code&gt;: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;Image&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Source&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;Binding&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Path&lt;/span&gt;=Image,&lt;span style="color:#ff0000"&gt; Source&lt;/span&gt;={&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Resources&lt;/span&gt;},&lt;span style="color:#ff0000"&gt; Converter&lt;/span&gt;={&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; BitmapToImageSourceConverter&lt;/span&gt;}}"/&amp;gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Because the cost of fixing defects increases (dramatically) as a product gets closer to shipping, it's important to find and fix issues as early as possible. Localization can be a tricky thing to get all the kinks worked out of, so it's helpful to have good tools around to ensure a team is following good practices. With its low cost, simple implementation and friction-free usage model, I'm hopeful &lt;code&gt;PseudoLocalizer&lt;/code&gt; will become another good tool to help people localize successfully! &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10121146" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Technical/">Technical</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/WPF/">WPF</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category></item><item><title>"Might as well face it, you're addicted to blob..." [BlobStoreApi update adds container management, fragmented response handling, other improvements, and enhanced Amazon S3 support by Delay.Web.Helpers!]</title><link>http://blogs.msdn.com/b/delay/archive/2011/01/20/quot-might-as-well-face-it-you-re-addicted-to-blob-quot-blobstoreapi-update-adds-container-management-fragmented-response-handling-other-improvements-and-enhanced-amazon-s3-support-by-delay-web-helpers.aspx</link><pubDate>Thu, 20 Jan 2011 17:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10118256</guid><dc:creator>David Anson</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10118256</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2011/01/20/quot-might-as-well-face-it-you-re-addicted-to-blob-quot-blobstoreapi-update-adds-container-management-fragmented-response-handling-other-improvements-and-enhanced-amazon-s3-support-by-delay-web-helpers.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;As part of my &lt;a href="http://blogs.msdn.com/b/delay/archive/2011/01/13/there-s-a-blob-on-your-web-page-but-don-t-wipe-it-off-new-delay-web-helpers-assembly-brings-easy-amazon-s3-blob-access-to-asp-net-web-sites.aspx"&gt;previous post announcing the &lt;code&gt;Delay.Web.Helpers&lt;/code&gt; assembly for ASP.NET and introducing the &lt;code&gt;AmazonS3Storage&lt;/code&gt; class to enable easy &lt;/a&gt;&lt;a href="http://aws.amazon.com/s3/"&gt;Amazon Simple Storage Service (S3)&lt;/a&gt; blob access from MVC/Razor/WebMatrix web pages&lt;a&gt;&lt;/a&gt;, I made some changes to the &lt;code&gt;BlobStoreApi.cs&lt;/code&gt; file it built on top of. &lt;code&gt;BlobStoreApi.cs&lt;/code&gt; was originally released as part of my &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/05/13/gettin-blobby-with-it-sharing-the-code-for-a-simple-silverlight-4-rest-based-cloud-oriented-file-management-app-for-azure-and-s3.aspx"&gt;BlobStore sample for Silverlight&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/10/12/is-that-a-blob-in-your-pocket-or-are-you-just-happy-to-see-me-silverlight-rest-based-azure-s3-blob-api-updated-to-run-on-windows-phone-7.aspx"&gt;BlobStoreOnWindowsPhone sample for Windows Phone 7&lt;/a&gt;; I'd made a note to update those two samples with the latest version of the code, but intended to blog about a few &lt;em&gt;other&lt;/em&gt; things first... &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Fragmented response handling&lt;/strong&gt;&lt;/p&gt;
&lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/6813.BlobStoreOnWindowsPhone.png" alt="BlobStoreOnWindowsPhone sample" style="float:right;margin-left:10px" /&gt;
&lt;p&gt;That's when I was contacted by &lt;a href="http://blog.smarx.com/"&gt;Steve Marx&lt;/a&gt; of the Azure team to see if I could help out &lt;a href="http://twitter.com/epweet"&gt;Erik Petersen&lt;/a&gt; of the Windows Phone team who was suddenly seeing a problem when using &lt;code&gt;BlobStoreApi&lt;/code&gt;: calls to &lt;code&gt;GetBlobInfos&lt;/code&gt; were returning only &lt;strong&gt;some&lt;/strong&gt; of the blobs instead of the complete list. Fortunately, Steve knew what was wrong without even looking - &lt;a href="http://blog.smarx.com/posts/windows-azure-tables-expect-continuation-tokens-seriously"&gt;he'd blogged about the underlying cause over a year ago&lt;/a&gt;! Although Windows Azure can return up to 5,000 blobs in response to a query, it may decide (at any time) to return &lt;strong&gt;fewer&lt;/strong&gt; (possibly as few as 0!) and instead include a token for getting the rest of the results from a subsequent call. This behavior is deterministic according to where the data is stored in the Azure cloud, but from the point of view of a developer it's probably safest to assume it's random. :) &lt;/p&gt;
&lt;p&gt;So something had changed for Erik's container and now he was getting partial results because my &lt;code&gt;BlobStoreApi&lt;/code&gt; code didn't know what to do with the "fragmented response" it had started getting. Although I'd &lt;em&gt;like&lt;/em&gt; to blame the documentation for not making it clear that even very &lt;strong&gt;small&lt;/strong&gt; responses could be broken up, I really should have supported fragmented responses anyway so users would be able to work with more than 5,000 blobs. &lt;a href="http://en.wikipedia.org/wiki/Mea_culpa"&gt;Mea culpa...&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;I definitely wanted to add &lt;code&gt;BlobStoreApi&lt;/code&gt; support for fragmented Azure responses, but what about S3? Did my code have the same problem there? According to the documentation: &lt;strong&gt;yes&lt;/strong&gt;! Although I don't see mention of the same "random" fragmentation behavior Azure has, S3 enumerations are limited to 1,000 blobs at a time, so that code needs the same update in order to support customer scenarios with lots of blobs. Fortunately, the mechanism both services use to implement fragmentation is quite similar and I was able to add most of the new code to the common &lt;code&gt;RestBlobStoreClient&lt;/code&gt; base class and then refine it with service-specific tweaks in the sub-classes &lt;code&gt;AzureBlobStoreClient&lt;/code&gt; and &lt;code&gt;S3BlobStoreClient&lt;/code&gt;. &lt;/p&gt;
&lt;p&gt;Fortunately, the extra work to support fragmented responses is all handled internally and is therefore invisible to the developer. As such, it requires &lt;strong&gt;no&lt;/strong&gt; changes to existing applications beyond updating to the new &lt;code&gt;BlobStoreApi.cs&lt;/code&gt; file and recompiling! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Container support&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;While dealing with fragmented responses was fun and a definite improvement, it's not the kind of thing most people appreciate. People don't usually get excited over fixes, but they &lt;strong&gt;will&lt;/strong&gt; get weak-kneed for new features - so I decided to add container/bucket management, too! Specifically, it's now possible to use &lt;code&gt;BlobStoreApi&lt;/code&gt; to list, create, and delete Azure containers and S3 buckets using the following asynchronous methods: &lt;/p&gt;
&lt;pre style="color:#000000"&gt;&lt;span style="color:#0000ff"&gt;public abstract void&lt;/span&gt; GetContainers(&lt;span style="color:#2b91af"&gt;Action&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&amp;gt;&amp;gt; getContainersCompleted, &lt;span style="color:#2b91af"&gt;Action&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Exception&lt;/span&gt;&amp;gt; getContainersFailed);
&lt;span style="color:#0000ff"&gt;public abstract void&lt;/span&gt; CreateContainer(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; containerName, &lt;span style="color:#2b91af"&gt;Action&lt;/span&gt; createContainerCompleted, &lt;span style="color:#2b91af"&gt;Action&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Exception&lt;/span&gt;&amp;gt; createContainerFailed);
&lt;span style="color:#0000ff"&gt;public abstract void&lt;/span&gt; DeleteContainer(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; containerName, &lt;span style="color:#2b91af"&gt;Action&lt;/span&gt; deleteContainerCompleted, &lt;span style="color:#2b91af"&gt;Action&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;Exception&lt;/span&gt;&amp;gt; deleteContainerFailed);&lt;/pre&gt;
&lt;p&gt;To be clear, each instance of &lt;code&gt;AzureBlobStoreClient&lt;/code&gt; and &lt;code&gt;S3BlobStoreClient&lt;/code&gt; is still associated with a specific container (the one that was passed to its constructor) and its blob manipulation methods act only on &lt;strong&gt;that&lt;/strong&gt; container - but now it's able to manipulate other containers, too. &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: In an alternate universe, I might have made the new container methods &lt;a href="http://msdn.microsoft.com/en-us/library/98f28cdx.aspx"&gt;static&lt;/a&gt; because they don't have a notion of a "current" container the same way the blob methods do. However, what I want &lt;strong&gt;more&lt;/strong&gt; than that is to be able to leverage the existing infrastructure I already have in place for creating requests, authorizing them, handling responses, etc. - all of which take advantage of instance methods on &lt;code&gt;RestBlobStoreClient&lt;/code&gt; that &lt;code&gt;AzureBlobStoreClient&lt;/code&gt; and &lt;code&gt;S3BlobStoreClient&lt;/code&gt; override as necessary. In &lt;strong&gt;this&lt;/strong&gt; world, it's not possible to have static methods that are also &lt;a href="http://msdn.microsoft.com/en-us/library/9fkccyh4.aspx"&gt;virtual&lt;/a&gt;, so I sacrificed the desire for the former in order to achieve the efficiencies of the latter. Maybe one day I'll refactor things so it's possible to have the best of both worlds - but for now I recommend specifying a &lt;code&gt;null&lt;/code&gt; container name when creating instances of &lt;code&gt;AzureBlobStoreClient&lt;/code&gt; and &lt;code&gt;S3BlobStoreClient&lt;/code&gt; when you want to ensure they're used &lt;strong&gt;only&lt;/strong&gt; for container-specific operations (and not for blobs, too). &lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Other improvements&lt;/strong&gt;&lt;/p&gt;
&lt;img height="355" width="244" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/3660.DelayWebHelpers_2D00_AmazonS3Storage.png" alt="Delay.Web.Helpers AmazonS3Storage sample" style="float:right;margin-left:10px" /&gt;
&lt;p&gt;With containers getting a fair amount of love this release, it seemed appropriate to add a &lt;code&gt;containerName&lt;/code&gt; parameter to the &lt;code&gt;AzureBlobStoreClient&lt;/code&gt; constructor so it would look the same as &lt;code&gt;S3BlobStoreClient&lt;/code&gt;'s constructor. This minor &lt;strong&gt;breaking change&lt;/strong&gt; means it's now necessary to specify a container name when creating instances of &lt;code&gt;AzureBlobStoreClient&lt;/code&gt;. If you want to preserve the behavior of existing code (and don't want to have to remember that "$root" is the magic root container name for Azure (and previous default)), you can pass &lt;code&gt;AzureBlobStoreClient.RootContainerName&lt;/code&gt; for the container name. &lt;/p&gt;
&lt;p&gt;In the process of doing some testing of the &lt;code&gt;BlobStoreApi&lt;/code&gt; code, I realized I hadn't previously exposed a way for an application to find out about asynchronous method failures. While it's probably true that part of the reason someone uses Azure or S3 is so they don't &lt;strong&gt;need&lt;/strong&gt; to worry about failures, things can always go wrong and sometimes you really need to know when they do. So in addition to each asynchronous method taking a parameter for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.action.aspx"&gt;Action&lt;/a&gt; to run upon successful completion, they now &lt;strong&gt;also&lt;/strong&gt; take an &lt;code&gt;Action&amp;lt;Exception&amp;gt;&lt;/code&gt; parameter which they'll call (instead) when a failure occurs. This new parameter is necessary, so please provide a meaningful handler instead of passing &lt;code&gt;null&lt;/code&gt; and assuming things will always succeed. :) &lt;/p&gt;
&lt;p&gt;I've also added a set of new &lt;a href="http://msdn.microsoft.com/en-us/library/yt3yck0x.aspx"&gt;#define&lt;/a&gt;s to allow &lt;code&gt;BlobStoreApi&lt;/code&gt; users to easily remove unwanted functionality. Because they're either self-explanatory or simple, I'm not going to go into more detail here (please have a look at the code if you're interested): &lt;code&gt;BLOBSTOREAPI_PUBLIC&lt;/code&gt;, &lt;code&gt;BLOBSTOREAPI_NO_URIS&lt;/code&gt;, &lt;code&gt;BLOBSTOREAPI_NO_AZUREBLOBSTORECLIENT&lt;/code&gt;, &lt;code&gt;BLOBSTOREAPI_NO_S3BLOBSTORECLIENT&lt;/code&gt;, and &lt;code&gt;BLOBSTOREAPI_NO_ISOLATEDSTORAGEBLOBSTORECLIENT&lt;/code&gt;. &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: Actually, &lt;code&gt;BLOBSTOREAPI_PUBLIC&lt;/code&gt; deserves a brief note: with this release of the &lt;code&gt;BlobStoreApi&lt;/code&gt;, the classes it implements are no longer public by default (they're expected to be &lt;em&gt;consumed&lt;/em&gt;, not &lt;em&gt;exposed&lt;/em&gt;). This represents a minor &lt;strong&gt;breaking change&lt;/strong&gt;, but the trivial fix is to &lt;code&gt;#define BLOBSTOREAPI_PUBLIC&lt;/code&gt; which restores things to being public as they were before. That said, it might be worth taking this opportunity to make the corresponding changes (if any) to your application - but that's entirely up to you and your schedule. &lt;/blockquote&gt;
&lt;p&gt;The last thing worth mentioning is that I've tweaked &lt;code&gt;BlobStoreApi&lt;/code&gt; to handle mixed-case blob/container names properly. Formerly, passing in upper-case characters for a blob name could result in failures for both Azure and S3; with this change in place, that scenario should work correctly. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;img height="479" width="602" src="http://blogs.msdn.com/blogfiles/delay/BlobStore-List.png" alt="BlobStore with silly sample data" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;New BlobStore and BlobStoreOnWindowsPhone samples&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I've updated the combined &lt;code&gt;BlobStore&lt;/code&gt;/&lt;code&gt;BlobStoreOnWindowsPhone&lt;/code&gt; download to include the latest version of &lt;code&gt;BlobStoreApi&lt;/code&gt; with all the changes outlined above. Although there are no new features in either sample, they both benefit from fragmented container support and demonstrate how to use the updated API methods properly. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/BlobStore/BlobStore.zip"&gt;[Click here to download the complete BlobStore source code and sample applications for both Silverlight 4 and Windows Phone 7.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;New Delay.Web.Helpers release and updated sample&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;Delay.Web.Helpers&lt;/code&gt; download includes the latest version of &lt;code&gt;BlobStoreApi&lt;/code&gt; (so it handles fragmented containers) &lt;strong&gt;and&lt;/strong&gt; includes new support for container management in the form of the following methods on the &lt;code&gt;AmazonS3Storage&lt;/code&gt; class: &lt;/p&gt;
&lt;pre style="color:#808080"&gt;/// &amp;lt;summary&amp;gt;
///&lt;span style="color:#008000"&gt; Lists the blob containers for an account.
&lt;/span&gt;/// &amp;lt;/summary&amp;gt;
/// &amp;lt;returns&amp;gt;&lt;span style="color:#008000"&gt;List of container names.&lt;/span&gt;&amp;lt;/returns&amp;gt;
&lt;span style="color:#0000ff"&gt;public static&lt;/span&gt;&lt;span style="color:#2b91af"&gt; IList&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="color:#000000"&gt;&amp;gt; ListBlobContainers() { ... }

&lt;/span&gt;/// &amp;lt;summary&amp;gt;
///&lt;span style="color:#008000"&gt; Creates a blob container.
&lt;/span&gt;/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="containerName"&amp;gt;&lt;span style="color:#008000"&gt;Container name.&lt;/span&gt;&amp;lt;/param&amp;gt;
&lt;span style="color:#0000ff"&gt;public static void&lt;/span&gt;&lt;span style="color:#000000"&gt; CreateBlobContainer(&lt;/span&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="color:#000000"&gt; containerName) { ... }

&lt;/span&gt;/// &amp;lt;summary&amp;gt;
///&lt;span style="color:#008000"&gt; Deletes an empty blob container.
&lt;/span&gt;/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name="containerName"&amp;gt;&lt;span style="color:#008000"&gt;Container name.&lt;/span&gt;&amp;lt;/param&amp;gt;
&lt;span style="color:#0000ff"&gt;public static void&lt;/span&gt;&lt;span style="color:#000000"&gt; DeleteBlobContainer(&lt;/span&gt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="color:#000000"&gt; containerName) { ... }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/b/delay/archive/2011/01/13/there-s-a-blob-on-your-web-page-but-don-t-wipe-it-off-new-delay-web-helpers-assembly-brings-easy-amazon-s3-blob-access-to-asp-net-web-sites.aspx"&gt;As I discuss in the introductory post for Delay.Web.Helpers&lt;/a&gt;, I'm deliberately matching the existing &lt;a href="http://azurestoragehelper.codeplex.com/"&gt;WindowsAzureStorage&lt;/a&gt; API with my implementation of &lt;code&gt;AmazonS3Storage&lt;/code&gt;, so these new methods look and function exactly the same for &lt;strong&gt;both&lt;/strong&gt; web services. As part of this release, I've also updated the &lt;code&gt;Delay.Web.Helpers&lt;/code&gt; sample page to show off the new container support as well as added some more automated tests to verify it. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/DelayWebHelpers/Delay.Web.Helpers.zip"&gt;[Click here to download the Delay.Web.Helpers assembly, its complete source code, all automated tests, and the sample web site.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;While I hadn't thought to get back to blobs quite so soon, finding out about the fragmented response issue kind of forced my hand. But all's well that ends well - I'm glad to have added container supported to &lt;code&gt;Delay.Web.Helpers&lt;/code&gt; because that means it now has complete blob-related feature parity with the &lt;code&gt;WindowsAzureStorage&lt;/code&gt; web helper and &lt;strong&gt;that&lt;/strong&gt; seems like a &lt;em&gt;Good Thing&lt;/em&gt;. What's more, I got confirmation that the &lt;a href="http://msdn.microsoft.com/en-us/library/dd179380.aspx"&gt;Windows Azure Managed Library&lt;/a&gt; does &lt;strong&gt;not&lt;/strong&gt; support Silverlight, so my &lt;code&gt;BlobStoreApi&lt;/code&gt; is serving duty as an unofficial substitute for now. [Which is cool! And a little scary... :) ] &lt;/p&gt;
&lt;p&gt;Whether you're using Silverlight on the desktop, writing a Windows Phone 7 application, or developing a web site with ASP.NET using MVC, Razor, or WebMatrix, I hope today's update helps your application offer just a little more goodness to your users! &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10118256" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Technical/">Technical</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Web+Platform/">Web Platform</category></item><item><title>Hash for the holidays [Managed implementation of CRC32 and MD5 algorithms updated; new release of ComputeFileHashes for Silverlight, WPF, and the command-line!]</title><link>http://blogs.msdn.com/b/delay/archive/2010/12/06/hash-for-the-holidays-managed-implementation-of-crc32-and-md5-algorithms-updated-new-release-of-computefilehashes-for-silverlight-wpf-and-the-command-line.aspx</link><pubDate>Mon, 06 Dec 2010 18:35:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10100917</guid><dc:creator>David Anson</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10100917</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2010/12/06/hash-for-the-holidays-managed-implementation-of-crc32-and-md5-algorithms-updated-new-release-of-computefilehashes-for-silverlight-wpf-and-the-command-line.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;It feels like a long time since I last wrote about &lt;a href="http://en.wikipedia.org/wiki/Hash_function"&gt;hash functions&lt;/a&gt; (though certain curmudgeonly coworkers would say not long enough!), and there were a few loose ends I've been meaning to deal with... &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: If my hashing efforts are new to you, more information can be found in my &lt;a href="http://blogs.msdn.com/b/delay/archive/2009/01/13/trust-but-verify-free-tool-and-source-code-for-computing-commonly-used-hash-codes.aspx"&gt;introduction to the ComputeFileHashes command-line tool&lt;/a&gt; and the subsequent &lt;a href="http://blogs.msdn.com/b/delay/archive/2009/01/21/gratuitous-platform-support-computefilehashes-works-on-the-command-line-on-wpf-on-silverlight-and-via-clickonce.aspx"&gt;release of ComputeFileHashes versions for the WPF and Silverlight platforms&lt;/a&gt;. &lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When I first needed a managed implementation of the &lt;a href="http://en.wikipedia.org/wiki/CRC32"&gt;CRC-32&lt;/a&gt; algorithm a while back, &lt;a href="http://blogs.msdn.com/b/delay/archive/2009/01/14/free-hash-a-reusable-crc-32-hashalgorithm-implementation-for-net.aspx"&gt;I ended up creating one from the reference implementation&lt;/a&gt;. Thanks to the strong similarities between &lt;a href="http://en.wikipedia.org/wiki/C_(programming_language)"&gt;C&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/C_Sharp_(programming_language)"&gt;C#&lt;/a&gt;, the algorithm itself required only minimal tweaks and the majority of my effort was packaging it up as a .NET &lt;a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.aspx"&gt;HashAlgorithm&lt;/a&gt;. Because &lt;code&gt;HashAlgorithm&lt;/code&gt; is the base class of all .NET hash functions, the &lt;code&gt;CRC32&lt;/code&gt; class ends up being trivial to drop into any .NET application that already deals with hashing. &lt;/p&gt;
&lt;img height="239" width="809" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/4174.ComputeFileHashes_2D00_WPF_2D00_201012.png" alt="ComputeFileHashesWPF" /&gt;
&lt;p&gt;The Silverlight platform doesn't include an implementation of the &lt;a href="http://en.wikipedia.org/wiki/Md5"&gt;MD5&lt;/a&gt; algorithm like "desktop" .NET does, and &lt;a href="http://blogs.msdn.com/b/delay/archive/2009/01/28/thank-goodness-for-reference-implementations-low-overhead-net-md5-implementation-source-code-and-tests-works-great-on-silverlight.aspx"&gt;I soon ended up creating an MD5 implementation from the reference code&lt;/a&gt; so I could support that algorithm on Silverlight (and now Windows Phone, too). Again, the C algorithm translated to C# fairly easily - though there's quite a lot more code for MD5 than CRC32 - and the &lt;code&gt;HashAlgorithm&lt;/code&gt; base class makes it easy to reuse. Over the next few days, I made a couple of &lt;a href="http://blogs.msdn.com/b/delay/archive/2009/01/23/math-is-hard-let-s-go-shopping-minor-bug-fix-for-free-crc-32-hashalgorithm-implementation-for-net.aspx"&gt;minor&lt;/a&gt; &lt;a href="http://blogs.msdn.com/b/delay/archive/2009/02/17/ambiguous-contract-is-ambiguous-minor-bug-fix-for-crc32-and-md5managed-hashalgorithm-implementations.aspx"&gt;revisions&lt;/a&gt; to the &lt;code&gt;CRC32&lt;/code&gt; and &lt;code&gt;MD5Managed&lt;/code&gt; classes, but have otherwise left things alone. I've used ComputeFileHashes successfully ever since, and things seemed to be in a pretty good state. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Then one day kind reader &lt;strong&gt;Maurizio&lt;/strong&gt; contacted me (from Italy!) to report a bug in my CRC32 wrapper: there was a missing variable in a loop that could lead to problems if someone passed a non-0 value as the &lt;code&gt;inputOffset&lt;/code&gt; parameter of &lt;a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.transformblock.aspx"&gt;TransformBlock&lt;/a&gt;. Fortunately, this isn't a particularly common scenario - the "primary" overload of &lt;a href="http://msdn.microsoft.com/en-us/library/s02tk69a.aspx"&gt;ComputeHash&lt;/a&gt; doesn't do it, none of my ComputeFileHashes code does it, and most typical scenarios probably won't do it, either. That said, a bug is a bug (is a bug), and I made a note to fix it when I got a chance... And I finally had that chance last week! :) &lt;/p&gt;
&lt;pre&gt;C:\T&amp;gt;ComputeFileHashesCL.exe ZeroByteFile.txt

C:\T\ZeroByteFile.txt
100.0%
CRC32: 00000000
MD5: D41D8CD98F00B204E9800998ECF8427E
SHA1: DA39A3EE5E6B4B0D3255BFEF95601890AFD80709
SHA256: E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855
SHA384: 38B060A751AC96384CD9327EB1B1E36A21FDB71114BE07434C0CC7BF63F6E1DA274EDEBFE76F65FBD51AD2F14898B95B
SHA512: CF83E1357EEFB8BDF1542850D66D8007D620E4050B5715DC83F4A921D36CE9CE47D0D13C5D85F2B0FF8318D2877EEC2F63B931BD47417A81A538327AF927DA3E
RIPEMD160: 9C1185A5C5E9FC54612808977EE8F548B2258D31&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And as long as I was already messing with the ComputeFileHashes code (which meant recompiling for each platform, re-packaging, uploading, etc.), there were a few other things I decided to take care of at the same time. And it's just as well - in the process of doing so, I discovered (and fixed) a seemingly obscure bug in &lt;code&gt;MD5Managed&lt;/code&gt; (which I suspect has never been hit in real life). Along the way, I added the complete suite of .NET &lt;code&gt;HashAlgorithm&lt;/code&gt;s to each tool so you'll automatically get the results of &lt;strong&gt;every&lt;/strong&gt; supported algorithm when you hash a file! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;ComputeFileHashes has been a fun project and a nice demonstration of how .NET lets you run the same code across a wide variety of environments and platforms. And the comprehensive automated test framework I added this time around makes me feel better about the correctness of these two &lt;code&gt;HashAlgorithm&lt;/code&gt;s. I deal with hashes regularly and have found all flavors of ComputeFileHashes to be handy tools to have around - especially the Silverlight version which brings simple, lightweight, install-free hashing to nearly every machine in the world. :) &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/ComputeFileHashes/ComputeFileHashes.zip"&gt;[Click here to download the complete source code for the command-line, Silverlight, and WPF implementations of ComputeFileHashes along with the new test project.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/r/SLHash"&gt;Click here or on the image below to run ComputeFileHashes in your browser with Silverlight 4&lt;/a&gt;: &lt;/strong&gt;&lt;/p&gt;
&lt;a href="http://cesso.org/r/SLHash"&gt;&lt;img height="332" width="892" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/7230.ComputeFileHashes_2D00_SL_2D00_201012.png" alt="ComputeFileHashesSL" /&gt;&lt;/a&gt;
&lt;p&gt;&lt;em&gt;Note: Bookmark the link above for easy access to hashing anytime, anywhere, on any machine! &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here are the major changes since last time: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;CRC32&lt;/code&gt; bug fix: HashCore was not adding the ibStart offset in its for loop.&lt;/strong&gt; This is the issue Maurizio reported and would affect all scenarios where a non-0 value was passed for &lt;code&gt;ibStart&lt;/code&gt;. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;MD5Managed&lt;/code&gt; bug fix: MD5Update was not adding the inputIndex offset in its call to MD5Transform.&lt;/strong&gt; This is the obscure issue found by the new test framework - in certain fairly specific circumstances (mostly around odd offsets and buffer sizes), the incorrect offset could result in an invalid hash result. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;All supported algorithms are run on each file.&lt;/strong&gt; Initially, only CRC32, MD5, and SHA1 were supported because they were the most common at the time and because I didn't want to waste CPU cycles on obscure algorithms that were hardly ever used. But since then, some of the "obscure" algorithms have become more common (ex: SHA256) and multi-core CPUs have become much more widespread. Because the ComputeFileHashes tools are already multi-processor friendly and because quad-processor CPUs are now commonplace, I've decided &lt;strong&gt;not&lt;/strong&gt; to limit them due to CPU cycles. Most files hash instantaneously anyway, so the additional algorithms won't slow things down there; for longer files where CPU might start to dominate over disk access, the additional overhead shouldn't be that big of a deal. With this release, the bias is for &lt;strong&gt;convenience&lt;/strong&gt;, and I'm optimistic that's the right tradeoff most of the time. :) &lt;/p&gt;
&lt;p&gt;Here's what each tool supports: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ComputeFileHashesCL&lt;/strong&gt;, &lt;strong&gt;ComputeFileHashesWPF&lt;/strong&gt;: CRC32, MD5, SHA1, SHA256, SHA384, SHA512, RIPEMD160 &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ComputeFileHashesSL&lt;/strong&gt;: CRC32, MD5, SHA1, SHA256 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;(Note: The Silverlight platform doesn't provide SHA384/SHA512/RIPEMD160. (And I haven't done my own implementation. (Yet...))) &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;There's a comprehensive set of automated tests for &lt;code&gt;CRC32&lt;/code&gt; and &lt;code&gt;MD5Managed&lt;/code&gt;.&lt;/strong&gt; I'd done some basic testing of this code in the past, but hadn't covered the edge cases - and a few bugs slipped by because of that. So I wanted to create a thorough automated test suite this time around and do what I could to cover all the bases. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The automated tests have a small library of different inputs and known-good hashes and process it in lots of different ways: all at once, in all different chunk sizes, with and without &lt;a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.initialize.aspx"&gt;Initialize&lt;/a&gt;, etc.. If &lt;strong&gt;any&lt;/strong&gt; of these techniques generates the wrong hash, the test suite reports the failure. &lt;/li&gt;
&lt;li&gt;The new tests are thorough enough to yield &lt;strong&gt;100% code coverage&lt;/strong&gt; on both the &lt;code&gt;CRC32&lt;/code&gt; and &lt;code&gt;MD5Managed&lt;/code&gt; implementations. &lt;/li&gt;
&lt;li&gt;In addition to testing my &lt;code&gt;CRC32&lt;/code&gt; and &lt;code&gt;MD5Managed&lt;/code&gt; classes, the automated tests &lt;strong&gt;also&lt;/strong&gt; test the .NET &lt;a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.md5cryptoserviceprovider.aspx"&gt;MD5CryptoServiceProvider&lt;/a&gt; class - not because I expect to find errors in it, but so I can ensure both MD5 implementations behave the &lt;strong&gt;same&lt;/strong&gt; in each scenario. &lt;/li&gt;
&lt;li&gt;Consequently (and as a result of the more thorough coverage) &lt;code&gt;CRC32&lt;/code&gt; and &lt;code&gt;MD5Managed&lt;/code&gt; now behave the same as the .NET implementations for &lt;strong&gt;in&lt;/strong&gt;valid scenarios, too - all the way to exception-level compatibility for misuse of the API! &lt;/li&gt;
&lt;li&gt;The only difference is for &lt;a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.cryptographicunexpectedoperationexception.aspx"&gt;CryptographicUnexpectedOperationException&lt;/a&gt; which can't be constructed on Silverlight - its base class &lt;a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.cryptographicexception.aspx"&gt;CryptographicException&lt;/a&gt; is thrown instead in cases where the hash value is retrieved before the process has been finalized. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The Visual Studio solution and project files have been upgraded to the Visual Studio 2010 format.&lt;/strong&gt; This makes developing ComputeFileHashes in Visual Studio 2010 easy and enables the use of its new and improved feature set. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The &lt;code&gt;CRC32&lt;/code&gt;/&lt;code&gt;MD5Managed&lt;/code&gt; classes and the three ComputeFileHashes programs are now code analysis-clean for the complete Visual Studio 2010 rule set.&lt;/strong&gt; Additional code analysis rules were introduced with VS 2010 and they reported some new violations in the code. These have all been fixed (or &lt;a href="http://msdn.microsoft.com/en-us/library/ms244717.aspx"&gt;suppressed&lt;/a&gt; where appropriate). &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The namespace of the &lt;code&gt;CRC32&lt;/code&gt; and &lt;code&gt;MD5Managed&lt;/code&gt; classes has been changed to "Delay".&lt;/strong&gt; This change brings these classes inline with the rest of the sample code I publish and makes their generality a bit clearer. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;ComputeFileHashesCL remains a .NET 2.0 application for maximum versatility.&lt;/strong&gt; By targeting .NET 2.0, ComputeFileHashesCL runs nearly everywhere .NET does. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;ComputeFileHashesWPF is now a .NET 4 application for compactness and ease of distribution.&lt;/strong&gt; ComputeFileHashesWPF used to have a dependency on the &lt;a href="http://wpf.codeplex.com/"&gt;WPFToolkit&lt;/a&gt; for its &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid(v=VS.100).aspx"&gt;DataGrid&lt;/a&gt; control. Because that control is part of the .NET 4 Framework, the new ComputeFileHashesWPF no longer depends on any non-Framework assemblies and can be distributed as a single file. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;ComputeFileHashesSL is now a Silverlight 4 application to make use of new features in that platform.&lt;/strong&gt; Most notably, ComputeFileHashesSL uses Silverlight's drag+drop support to enable the handy scenario of dragging a file directly from Windows Explorer and dropping it onto the ComputeFileHashesSL window to hash it (just like ComputeFileHashesWPF already supported). Additionally, I'm making use of my &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/11/10/the-taming-of-the-phone-new-settervaluebindinghelper-sample-demonstrates-its-usefulness-on-windows-phone-7-and-silverlight-4.aspx"&gt;SetterValueBindingHelper&lt;/a&gt; class to use &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding.aspx"&gt;Binding&lt;/a&gt;s in a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.setter.aspx"&gt;Setter&lt;/a&gt; and create the same &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.tooltip.aspx"&gt;ToolTip&lt;/a&gt; experience that ComputeFileHashesWPF already had: hovering over a hash failure shows the reason for the failure (typically because the file was locked by another process). Consequently, the "Details" column is no longer necessary in ComputeFileHashesSL and has been removed. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/t71a733d(v=VS.100).aspx"&gt;ClickOnce&lt;/a&gt; flavor of ComputeFileHashesWPF is no longer supported.&lt;/strong&gt; With ComputeFileHashesSL's functionality getting closer to that of ComputeFileHashesWPF and the elimination of the &lt;code&gt;WPFToolkit.dll&lt;/code&gt; dependency from ComputeFileHashesWPF, the need for a ClickOnce install seems minimal and has been removed. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The version number has been updated to 2010-11-30.&lt;/strong&gt; &lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10100917" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Technical/">Technical</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/WPF/">WPF</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Utilities/">Utilities</category></item><item><title>Better together [DynamicOrientationChanges and TransitionFrame create a comprehensive transition experience for Windows Phone 7]</title><link>http://blogs.msdn.com/b/delay/archive/2010/11/29/better-together-dynamicorientationchanges-and-transitionframe-create-a-comprehensive-transition-experience-for-windows-phone-7.aspx</link><pubDate>Mon, 29 Nov 2010 20:40:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10097984</guid><dc:creator>David Anson</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10097984</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2010/11/29/better-together-dynamicorientationchanges-and-transitionframe-create-a-comprehensive-transition-experience-for-windows-phone-7.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;I've previously &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/28/this-one-s-for-you-gregor-mendel-code-to-animate-and-fade-windows-phone-orientation-changes-now-supports-a-new-mode-hybrid.aspx"&gt;blogged about my implementation of AnimateOrientationChangesFrame, FadeOrientationChangesFrame, and HybridOrientationChangesFrame&lt;/a&gt;. As part of my &lt;code&gt;DynamicOrientationChanges&lt;/code&gt; sample, these classes smoothly animate an application's layout transition as the phone orientation changes from portrait to landscape (and vice-versa). &lt;/p&gt;
&lt;img height="300" width="551" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/6136.DynamicOrientationChanges_2D00_Hybrid.png" alt="HybridOrientationChanges sample" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;More recently, &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/11/02/mo-controls-mo-controls-mo-controls-announcing-the-second-release-of-the-silverlight-for-windows-phone-toolkit.aspx"&gt;I blogged about the Windows Phone Toolkit's support for animated page transitions&lt;/a&gt;. The &lt;code&gt;TransitionFrame&lt;/code&gt; class (and its helpers) work with the &lt;a href="http://msdn.microsoft.com/en-us/library/ff402536(v=VS.92).aspx"&gt;platform's navigation framework&lt;/a&gt; to animate the transitions among different pages within an application. &lt;/p&gt;
&lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/4341.WpTkOct10_2D00_TransitionFrame.png" alt="TransitionFrame sample" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Though they address different scenarios, both transition helpers make it easy for developers' Silverlight applications to &lt;strong&gt;match&lt;/strong&gt; the behavior of the core Windows Phone 7 applications. The obvious question is whether it's possible to use them together... &lt;/p&gt;
&lt;p&gt;At first glance, the fact that both approaches work by directly subclassing &lt;a href="http://msdn.microsoft.com/en-us/library/ff402930(v=VS.92).aspx"&gt;PhoneApplicationFrame&lt;/a&gt; means they can't be combined as-is. &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: This is one of the drawbacks of subclassing as a method of adding or extending functionality in a library: you only get &lt;strong&gt;one&lt;/strong&gt; chance to subclass the base class. (But because you can create as many subclasses as you want, subclassing a subclass can be an excellent alternative!) &lt;/blockquote&gt;
&lt;p&gt;So it has always been my hope that these two approaches could be easily combined to create an application that animates &lt;strong&gt;both&lt;/strong&gt; kinds of transitions. Because the Windows Phone Toolkit's &lt;code&gt;TransitionFrame&lt;/code&gt; class is more official, it seems appropriate to leave that one alone and try subclassing the &lt;code&gt;DynamicOrientationChanges&lt;/code&gt; classes from &lt;code&gt;TransitionFrame&lt;/code&gt;. Based on what I knew about both implementations, I &lt;em&gt;assumed&lt;/em&gt; this would work, but I didn't get around to trying it before &lt;a href="http://mobileworld.appamundi.com/blogs/andywigley/default.aspx"&gt;Andy Wigley&lt;/a&gt; contacted me with the same question! Well, Andy was brave enough to give this a go and reports that it works well - he wrote a nice summary here: &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://mobileworld.appamundi.com/blogs/andywigley/archive/2010/11/24/best-of-breed-page-rotation-animations.aspx"&gt;Best of breed Page rotation animations &lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you're interested in combining these two scenarios, I &lt;strong&gt;highly&lt;/strong&gt; recommend checking out Andy's post - he's made the change easy to understand and the steps are easy to follow! &lt;/p&gt;
&lt;p&gt;&lt;em&gt;Thanks, Andy!&lt;/em&gt; :) &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;PS&lt;/strong&gt; - If others have success merging the two transition animation implementations, I'll go ahead and make this an official part of the &lt;code&gt;DynamicOrientationChanges&lt;/code&gt; project in a future release. Please don't be shy - give it a try and let me know how it goes! &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10097984" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone+Toolkit/">Windows Phone Toolkit</category></item><item><title>You've got questions; I've got dumb looks [PDC10's Channel 9 Live Windows Phone 7 Q&amp;A session available online and offline]</title><link>http://blogs.msdn.com/b/delay/archive/2010/11/22/you-ve-got-questions-i-ve-got-dumb-looks-pdc10-s-channel-9-live-windows-phone-7-q-amp-a-session-available-online-and-offline.aspx</link><pubDate>Mon, 22 Nov 2010 19:18:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10095079</guid><dc:creator>David Anson</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10095079</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2010/11/22/you-ve-got-questions-i-ve-got-dumb-looks-pdc10-s-channel-9-live-windows-phone-7-q-amp-a-session-available-online-and-offline.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;A few weeks ago, Microsoft held its annual &lt;a href="http://www.microsoftpdc.com/"&gt;Professional Developer's Conference (PDC10)&lt;/a&gt; and I had the privilege of being a (small!) part of it. This year's content spanned a variety of topics, including &lt;a href="http://www.microsoft.com/windowsazure/"&gt;Windows Azure&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/Html5"&gt;HTML 5&lt;/a&gt;, &lt;a href="http://www.microsoft.com/windowsphone/en-us/default.aspx"&gt;Windows Phone 7&lt;/a&gt;, and &lt;strong&gt;more&lt;/strong&gt;! The &lt;a href="http://channel9.msdn.com/"&gt;Channel 9&lt;/a&gt; folks were there in force with two full days of live interviews - including a session on Windows Phone 7 Questions &amp;amp; Answers. Under the expert direction of &lt;a href="http://blogs.msdn.com/b/danielfe/"&gt;Dan Fernandez&lt;/a&gt;, team members &lt;a href="http://www.jeff.wilcox.name/blog/"&gt;Jeff Wilcox&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/b/ptorr/"&gt;Peter Torr&lt;/a&gt;, and &lt;a href="http://blogs.msdn.com/b/delay/"&gt;myself&lt;/a&gt; spent about 30 minutes talking about building Windows Phone 7 applications and answering questions from the (virtual) audience. It was a lot of &lt;strong&gt;fun&lt;/strong&gt;, and I'd like to think it might even be educational! :) &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;img height="240" width="424" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/2671.Channel9Pdc10WindowsPhone7QA.jpg" alt="Channel 9 Windows Phone 7 Question and Answer session" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here are the viewing options: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://player.microsoftpdc.com/Session/aa8ed0d8-8199-49fe-979f-7016b3d83c94"&gt;For live streaming, click here and advance 55 minutes into the stream.&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://videoaz.microsoftpdc.com/vod/pdc10_pre_event/ShowContent_VOD/Channel9/CH9_Day2_WP7ControlsQA_PDC_MP4_High_480p_1500k.mp4"&gt;For a high bandwidth MP4 download, click here.&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://videoaz.microsoftpdc.com/vod/pdc10_pre_event/ShowContent_VOD/Channel9/CH9_Day2_WP7ControlsQA_PDC_MP4_Low_device_480x272_750k.mp4"&gt;For a low bandwidth MP4 download, click here.&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://videoaz.microsoftpdc.com/vod/pdc10_pre_event/ShowContent_VOD/Channel9/CH9_Day2_WP7ControlsQA_PDC_WMV_High_480p_1500k.wmv"&gt;For a high bandwidth WMV download, click here.&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="http://videoaz.microsoftpdc.com/vod/pdc10_pre_event/ShowContent_VOD/Channel9/CH9_Day2_WP7ControlsQA_PDC_WMV_Low_640x360_1000k.wmv"&gt;Fro a low bandwidth WMV download, click here.&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;While you're at it, please check out some of the &lt;a href="http://www.microsoftpdc.com/"&gt;&lt;strong&gt;other&lt;/strong&gt; PDC10 content online&lt;/a&gt; - there's a ton of good stuff and it's all &lt;strong&gt;free&lt;/strong&gt; to enjoy! &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10095079" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone+Toolkit/">Windows Phone Toolkit</category></item><item><title>The taming of the phone [New SetterValueBindingHelper sample demonstrates its usefulness on Windows Phone 7 (and Silverlight 4)]</title><link>http://blogs.msdn.com/b/delay/archive/2010/11/10/the-taming-of-the-phone-new-settervaluebindinghelper-sample-demonstrates-its-usefulness-on-windows-phone-7-and-silverlight-4.aspx</link><pubDate>Wed, 10 Nov 2010 17:55:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10089023</guid><dc:creator>David Anson</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10089023</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2010/11/10/the-taming-of-the-phone-new-settervaluebindinghelper-sample-demonstrates-its-usefulness-on-windows-phone-7-and-silverlight-4.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;If you've done much work with &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding(v=VS.95).aspx"&gt;Binding&lt;/a&gt;s in Silverlight, you're probably aware that Silverlight doesn't support applying &lt;code&gt;Binding&lt;/code&gt;s using a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.style(VS.95).aspx"&gt;Style&lt;/a&gt;'s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.setter(v=VS.95).aspx"&gt;Setter&lt;/a&gt; the same way its big brother WPF does. This limitation isn't a big deal at first because people don't tend to need that until they're more familiar with the platform and have started using &lt;a href="http://en.wikipedia.org/wiki/MVVM"&gt;MVVM&lt;/a&gt; and taking advantage of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox.itemcontainerstyle(VS.95).aspx"&gt;ItemContainerStyle&lt;/a&gt; property. But once you're working with scenarios where it's relevant, being able to specify &lt;code&gt;Binding&lt;/code&gt;s in a &lt;code&gt;Setter&lt;/code&gt; can be &lt;strong&gt;extremely&lt;/strong&gt; useful because it replaces a bunch of code/subclassing with a single line of XAML! &lt;/p&gt;
&lt;img height="380" width="488" src="http://blogs.msdn.com/blogfiles/delay/SetterValueBindingHelperDemo.png" alt="SetterValueBindingHelperDemo sample on Silverlight" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Fortunately, it's possible to implement this feature &lt;strong&gt;outside&lt;/strong&gt; the Silverlight framework! (Or at least to implement enough of it to cover nearly all the relevant scenarios.) &lt;a href="http://blogs.msdn.com/b/delay/archive/2009/05/07/one-more-platform-difference-more-or-less-tamed-settervaluebindinghelper-makes-silverlight-setters-better.aspx"&gt;I originally wrote SetterValueBindingHelper for Silverlight 3 as part of an application building exercise&lt;/a&gt;. Later on, &lt;a href="http://blogs.msdn.com/b/delay/archive/2009/11/02/as-the-platform-evolves-so-do-the-workarounds-better-settervaluebindinghelper-makes-silverlight-setters-better-er.aspx"&gt;I updated SetterValueBindingHelper to accommodate implementation changes in the Silverlight 4 platform&lt;/a&gt; - and was able to do so in a way that continued to work on Silverlight 3. So because Windows Phone 7 is based on Silverlight 3, I had a strong suspicion &lt;code&gt;SetterValueBindingHelper&lt;/code&gt; would work there, too. But it wasn't until a couple of days ago that I had a chance to validate my theory - and now that I &lt;strong&gt;have&lt;/strong&gt;, here's an updated version of the Silverlight sample for Windows Phone: &lt;/p&gt;
&lt;img height="316" width="528" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/2664.SetterValueBindingHelperDemoOnWindowsPhone.PNG" alt="SetterValueBindingHelperDemo sample on Windows Phone 7" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Other than converting the Silverlight sample's &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.treeview(v=VS.95).aspx"&gt;TreeView&lt;/a&gt; to a &lt;a href="http://msdn.microsoft.com/en-us/library/ms611062(v=VS.95).aspx"&gt;ListBox&lt;/a&gt; (because the former doesn't exist for Windows Phone), the sample works just the &lt;strong&gt;same&lt;/strong&gt; on Windows Phone as on Silverlight. The code for &lt;code&gt;SetterValueBindingHelper&lt;/code&gt; is nearly identical as well - the only difference being that the code to walk an application's assemblies for resolving attached property types can't be used because Windows Phone doesn't support the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.assemblypart.load(v=VS.95).aspx"&gt;AssemblyPart.Load&lt;/a&gt; method. (But because this particular feature isn't used very often, its absence probably won't even be noticed.) &lt;/p&gt;
&lt;p&gt;As a quick reminder, here's what a typical use looks like: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;ListBox.ItemContainerStyle&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;Style&lt;/span&gt;&lt;span style="color:#ff0000"&gt; TargetType&lt;/span&gt;="ListBoxItem"&amp;gt;
&lt;span style="color:#008000"&gt;        &amp;lt;!-- WPF syntax:
            &amp;lt;Setter Property="Foreground" Value="{Binding Color}"/&amp;gt; --&amp;gt;
&lt;/span&gt;        &amp;lt;&lt;span style="color:#a31515"&gt;Setter&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Property&lt;/span&gt;="delay:SetterValueBindingHelper.PropertyBinding"&amp;gt;
            &amp;lt;&lt;span style="color:#a31515"&gt;Setter.Value&lt;/span&gt;&amp;gt;
                &amp;lt;&lt;span style="color:#a31515"&gt;delay&lt;/span&gt;:&lt;span style="color:#a31515"&gt;SetterValueBindingHelper
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;                    Property&lt;/span&gt;="Foreground"
&lt;span style="color:#ff0000"&gt;                    Binding&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;Binding&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Color&lt;/span&gt;}"/&amp;gt;
            &amp;lt;/&lt;span style="color:#a31515"&gt;Setter.Value&lt;/span&gt;&amp;gt;
        &amp;lt;/&lt;span style="color:#a31515"&gt;Setter&lt;/span&gt;&amp;gt;
    &amp;lt;/&lt;span style="color:#a31515"&gt;Style&lt;/span&gt;&amp;gt;
&amp;lt;/&lt;span style="color:#a31515"&gt;ListBox.ItemContainerStyle&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: &lt;code&gt;SetterValueBindingHelper&lt;/code&gt; supports more advanced scenarios, too - please refer to the &lt;a href="http://blogs.msdn.com/b/delay/archive/2009/11/02/as-the-platform-evolves-so-do-the-workarounds-better-settervaluebindinghelper-makes-silverlight-setters-better-er.aspx"&gt;previous post&lt;/a&gt; (or the &lt;a href="http://blogs.msdn.com/b/delay/archive/2009/05/07/one-more-platform-difference-more-or-less-tamed-settervaluebindinghelper-makes-silverlight-setters-better.aspx"&gt;original post&lt;/a&gt;) for information and examples. &lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/SetterValueBindingHelperDemo/SetterValueBindingHelperDemo.zip"&gt;[Click here to download the code for SetterValueBindingHelper along with sample applications for Silverlight 4 and Windows Phone 7.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I've gotten a lot of great feedback from developers who have made use of &lt;code&gt;SetterValueBindingHelper&lt;/code&gt; in their applications. I've found it quite helpful in my own projects, and I'm glad many of &lt;strong&gt;you&lt;/strong&gt; have, too! With today's announcement, I hope another "generation" is able to use &lt;code&gt;SetterValueBindingHelper&lt;/code&gt; to benefit from the many advantages of the Silverlight platform's rich data-binding support. :) &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10089023" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category></item><item><title>ListPicker? I hardly even know 'er! [A detailed overview of the Windows Phone Toolkit's ListPicker control]</title><link>http://blogs.msdn.com/b/delay/archive/2010/11/03/listpicker-i-hardly-even-know-er-a-detailed-overview-of-the-windows-phone-toolkit-s-listpicker-control.aspx</link><pubDate>Wed, 03 Nov 2010 18:27:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10085617</guid><dc:creator>David Anson</dc:creator><slash:comments>44</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10085617</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2010/11/03/listpicker-i-hardly-even-know-er-a-detailed-overview-of-the-windows-phone-toolkit-s-listpicker-control.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;In yesterday's post, &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/11/02/mo-controls-mo-controls-mo-controls-announcing-the-second-release-of-the-silverlight-for-windows-phone-toolkit.aspx"&gt;I announced the second release of the Silverlight for Windows Phone Toolkit&lt;/a&gt; and gave an overview of the four new controls it includes. (For a discussion of the controls in the &lt;em&gt;original&lt;/em&gt; Windows Phone Toolkit, &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/16/pining-for-windows-phone-7-controls-we-got-ya-covered-announcing-the-first-release-of-the-silverlight-for-windows-phone-toolkit.aspx"&gt;please see my announcement for that release&lt;/a&gt;.) In today's post, I want to focus on one of the new controls, &lt;code&gt;ListPicker&lt;/code&gt;, and discuss it in detail. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The &lt;a href="http://silverlight.codeplex.com/releases/view/55034"&gt;sample application associated with the official Windows Phone Toolkit download&lt;/a&gt; offers a great overview of the Windows Phone Toolkit controls, but (deliberately) doesn't get into specific detail on any of them. This post is all about details, so I've written a dedicated sample application which is the source of all the XAML snippets and screenshots below: &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/ListPickerSamples/ListPickerSamples.zip"&gt;[Click here to download the complete source code for the ListPickerSamples application.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Background&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;From my previous post: &lt;/p&gt;
&lt;blockquote&gt;&lt;code&gt;ListPicker&lt;/code&gt; is the Windows Phone 7 equivalent of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.combobox(VS.95).aspx"&gt;ComboBox&lt;/a&gt; control: give it a list of items and it will show the selected one and also allowing the user to pick from a list if they want to change it. The core applications on Windows Phone 7 implement &lt;strong&gt;two&lt;/strong&gt; kinds of list selection: an in-place expander for picking among five or fewer items, and a full-screen popup for picking among more. The Toolkit's &lt;code&gt;ListPicker&lt;/code&gt; control combines both experiences into one handy package by &lt;strong&gt;automatically&lt;/strong&gt; selecting the right UX based on the number of items in its list! It is a standard &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol(VS.95).aspx"&gt;ItemsControl&lt;/a&gt; subclass with all the common elements of a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector(v=VS.95).aspx"&gt;Selector&lt;/a&gt;, so the API will be familiar to just about everyone. In fact, you can take most existing &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox(VS.95).aspx"&gt;ListBox&lt;/a&gt;es and convert them to &lt;code&gt;ListPicker&lt;/code&gt;s just by changing the control name in XAML! &lt;/blockquote&gt;
&lt;p&gt;That's the gist: &lt;em&gt;&lt;code&gt;ListPicker&lt;/code&gt; is the control of choice for selecting values in Windows Phone 7 applications.&lt;/em&gt; To be more explicit, it is &lt;strong&gt;most&lt;/strong&gt; appropriate in "Settings"-like scenarios where the user is offered a variety of different options and it makes sense to display only the current value (with an option to show everything once the user decides to make a change). Conversely, &lt;code&gt;ListPicker&lt;/code&gt; is &lt;strong&gt;not&lt;/strong&gt; appropriate for displaying long lists of data that the user is going to scan and scroll; scenarios like the "People" or "Marketplace" applications are better served by a &lt;code&gt;ListBox&lt;/code&gt; or the Windows Phone Toolkit's new &lt;code&gt;LongListSelector&lt;/code&gt;. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Typical Use&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The most common scenario for &lt;code&gt;ListPicker&lt;/code&gt; looks something like this: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;StackPanel&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;ListPicker&lt;/span&gt;
&lt;span style="color:#ff0000"&gt;        Header&lt;/span&gt;="Rating"
&lt;span style="color:#ff0000"&gt;        ItemsSource&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;Binding&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Ratings&lt;/span&gt;}"
&lt;span style="color:#ff0000"&gt;        SelectedIndex&lt;/span&gt;="1"
&lt;span style="color:#ff0000"&gt;        SelectionChanged&lt;/span&gt;="RatingSelectionChanged"/&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;TextBlock
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;        x&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;Name&lt;/span&gt;="RatingSelection"
&lt;span style="color:#ff0000"&gt;        CacheMode&lt;/span&gt;="BitmapCache"/&amp;gt;
    ...
&amp;lt;/&lt;span style="color:#a31515"&gt;StackPanel&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;p&gt;Which gets displayed like this (in normal and expanded forms): &lt;/p&gt;
&lt;img height="87" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/2656.ListPickerOverview_2D00_TypicalNormal.png" align="top" alt="Typical example (normal)" /&gt; &lt;img height="155" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/2843.ListPickerOverview_2D00_TypicalExpanded.png" alt="Typical example (expanded)" /&gt;
&lt;p&gt;As you'd expect for an &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol(VS.95).aspx"&gt;ItemsControl&lt;/a&gt; subclass, the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemssource(v=VS.95).aspx"&gt;ItemsSource&lt;/a&gt; property is used to provide the list of items (see also: the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.items(v=VS.95).aspx"&gt;Items&lt;/a&gt; property). And as you'd expect for a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector(v=VS.95).aspx"&gt;Selector&lt;/a&gt;-like control, the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector.selectionchanged(v=VS.95).aspx"&gt;SelectionChanged&lt;/a&gt; event is used to signal changes and the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector.selectedindex(v=VS.95).aspx"&gt;SelectedIndex&lt;/a&gt; property is used to get or set the selection (see also: &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector.selecteditem(v=VS.95).aspx"&gt;SelectedItem&lt;/a&gt;). Everything so far looks just like &lt;code&gt;ListBox&lt;/code&gt; - the only difference is the &lt;code&gt;Header&lt;/code&gt; property which can optionally be used to provide a simple, platform-consistent label for the &lt;code&gt;ListPicker&lt;/code&gt; that offers additional context about the control's purpose (see also: &lt;code&gt;HeaderTemplate&lt;/code&gt;). &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: The built-in &lt;code&gt;List&lt;strong&gt;Box&lt;/strong&gt;&lt;/code&gt; control will throw an exception if you set &lt;code&gt;SelectedIndex&lt;/code&gt; as in the example above because it tries to apply the selection &lt;strong&gt;before&lt;/strong&gt; the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.data.binding(v=VS.95).aspx"&gt;Binding&lt;/a&gt; has provided the list of items. &lt;code&gt;List&lt;strong&gt;Picker&lt;/strong&gt;&lt;/code&gt; specifically handles this common scenario so you don't have to jump through hoops to make it work. :) &lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Custom Templates&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Displaying strings is all well and good, but sometimes it's nice to display richer content: &lt;/p&gt;
&lt;img height="64" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/5074.ListPickerOverview_2D00_TemplateNormal.png" align="top" alt="Custom template (normal)" /&gt; &lt;img height="259" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/6076.ListPickerOverview_2D00_TemplateFull.png" alt="Custom template (expanded)" /&gt;
&lt;p&gt;The first thing to do is set the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemtemplate(v=VS.95).aspx"&gt;ItemTemplate&lt;/a&gt; property as you would for &lt;code&gt;ItemsControl&lt;/code&gt; or &lt;code&gt;ListBox&lt;/code&gt; - that applies the specified &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.datatemplate(v=VS.95).aspx"&gt;DataTemplate&lt;/a&gt; to each item and formats it attractively in the usual manner. That works great, but what about &lt;code&gt;ListPicker&lt;/code&gt;'s &lt;code&gt;Full&lt;/code&gt; mode that's used when the list has too many items? By default, the &lt;strong&gt;same&lt;/strong&gt; &lt;code&gt;ItemTemplate&lt;/code&gt; automatically applies there, too, so you may not need to do anything more! However, the &lt;code&gt;Full&lt;/code&gt; mode UI uses the entire screen, so it's pretty common to want to specifically customize the appearance of the items for that mode. Therefore, the &lt;code&gt;FullModeItemTemplate&lt;/code&gt; property lets you provide a &lt;strong&gt;different&lt;/strong&gt; &lt;code&gt;DataTemplate&lt;/code&gt; to be used in the &lt;code&gt;Full&lt;/code&gt; mode scenario. Another relevant property for such cases is &lt;code&gt;FullModeHeader&lt;/code&gt; which sets the content that's shown at the top of the full-screen "popup". &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;ListPicker
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;    Header&lt;/span&gt;="Spectrum"
&lt;span style="color:#ff0000"&gt;    FullModeHeader&lt;/span&gt;="CHOOSE COLOR"
&lt;span style="color:#ff0000"&gt;    ItemsSource&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;Binding&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Rainbow&lt;/span&gt;}"
&lt;span style="color:#ff0000"&gt;    ItemTemplate&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; RainbowTemplate&lt;/span&gt;}"
&lt;span style="color:#ff0000"&gt;    FullModeItemTemplate&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; LargeRainbowTemplate&lt;/span&gt;}"/&amp;gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Threshold Overrides&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;By default, lists with five or fewer items expand in-place while lists with more items switch to a full-screen selection interface. This behavior matches the platform guidelines, but sometimes it might make sense to nudge the threshold one way or another (for very large or very small items, perhaps). You might even want to force a &lt;code&gt;ListPicker&lt;/code&gt; to &lt;strong&gt;always&lt;/strong&gt; use &lt;code&gt;Expanded&lt;/code&gt; or &lt;code&gt;Full&lt;/code&gt; mode... &lt;/p&gt;
&lt;img height="105" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/6064.ListPickerOverview_2D00_ThresholdFull.png" align="top" alt="Threshold (full)" /&gt; &lt;img height="177" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/3252.ListPickerOverview_2D00_ThresholdExpanded.png" alt="Threshold (expanded)" /&gt;
&lt;p&gt;For these scenarios, there's the &lt;code&gt;ItemCountThreshold&lt;/code&gt; property: it specifies the maximum number of items that will be displayed in &lt;code&gt;Expanded&lt;/code&gt; mode. In addition to nudging it up or down a bit for custom scenarios, it can also be set to 0 to "always use &lt;code&gt;Full&lt;/code&gt; mode" or a very large number to "always use &lt;code&gt;Expanded&lt;/code&gt; mode". Granted, an application that forces &lt;code&gt;Expanded&lt;/code&gt; mode for a list of 1000 items probably won't be easy to use - but the freedom is there to allow developers and designers to dial-in &lt;strong&gt;exactly&lt;/strong&gt; the kind of experience they want. &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;ListPicker
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;    Header&lt;/span&gt;="Rating"
&lt;span style="color:#ff0000"&gt;    FullModeHeader&lt;/span&gt;="CHOOSE RATING"
&lt;span style="color:#ff0000"&gt;    ItemsSource&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;Binding&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Ratings&lt;/span&gt;}"
&lt;span style="color:#ff0000"&gt;    ItemCountThreshold&lt;/span&gt;="0"/&amp;gt;
&amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;ListPicker
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;    Header&lt;/span&gt;="Spectrum"
&lt;span style="color:#ff0000"&gt;    ItemsSource&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;Binding&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Rainbow&lt;/span&gt;}"
&lt;span style="color:#ff0000"&gt;    ItemTemplate&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; RainbowTemplate&lt;/span&gt;}"
&lt;span style="color:#ff0000"&gt;    ItemCountThreshold&lt;/span&gt;="100"/&amp;gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Two-Way Binding&lt;/strong&gt;&lt;/p&gt;
&lt;img height="88" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/8623.ListPickerOverview_2D00_TwoWay.png" alt="Two-way binding" /&gt;
&lt;p&gt;As you'd expect, &lt;code&gt;ListPicker&lt;/code&gt; can be used with &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.data.bindingmode(v=VS.95).aspx"&gt;TwoWay&lt;/a&gt; &lt;code&gt;Binding&lt;/code&gt;s as well. This is particularly convenient for the &lt;code&gt;SelectedIndex&lt;/code&gt;/&lt;code&gt;SelectedItem&lt;/code&gt; properties where it's common to want to set the initial value based on a data model (see also: &lt;a href="http://en.wikipedia.org/wiki/MVVM"&gt;MVVM&lt;/a&gt;) and/or when you want the model to update directly when selection changes. The corresponding XAML looks just how you'd expect: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;ListPicker
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;    Header&lt;/span&gt;="Network"
&lt;span style="color:#ff0000"&gt;    ItemsSource&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;Binding&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Networks&lt;/span&gt;}"
&lt;span style="color:#ff0000"&gt;    SelectedItem&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;Binding&lt;/span&gt;&lt;span style="color:#ff0000"&gt; CurrentNetwork&lt;/span&gt;,&lt;span style="color:#ff0000"&gt; Mode&lt;/span&gt;=TwoWay}"/&amp;gt;
&amp;lt;&lt;span style="color:#a31515"&gt;StackPanel
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;    Orientation&lt;/span&gt;="Horizontal"
&lt;span style="color:#ff0000"&gt;    Margin&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; PhoneMargin&lt;/span&gt;}"
&lt;span style="color:#ff0000"&gt;    CacheMode&lt;/span&gt;="BitmapCache"&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Text&lt;/span&gt;="Current Network: "/&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Text&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;Binding&lt;/span&gt;&lt;span style="color:#ff0000"&gt; CurrentNetwork&lt;/span&gt;}"/&amp;gt;
&amp;lt;/&lt;span style="color:#a31515"&gt;StackPanel&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Tips and Tricks&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;At this point, I hope everyone knows how &lt;code&gt;ListPicker&lt;/code&gt; works and has a good feel for when/where/why/how to use it. That being the case, there are a few additional things I'd like to draw attention to: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;The &lt;code&gt;ListPicker&lt;/code&gt; philosophy is that "there is always an active selection", so it makes sure to select an item when it initializes or when the list changes. This automatic selection (of the first item in most cases) causes the &lt;code&gt;SelectionChanged&lt;/code&gt; event to fire - and that causes the application's associated event handler to run (assuming one has been registered). In practice, this "initialization-time" event catches some people by surprise - but it's the intended behavior (and folks tend to agree it's correct once they understand why it happens). Now that &lt;strong&gt;you&lt;/strong&gt; know about it, maybe your development experience will be a bit easier. :) &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: If you want to ignore this event in code, it should be easy to detect because its &lt;a href="http://msdn.microsoft.com/en-us/library/ms605410(v=VS.95).aspx"&gt;SelectionChangedEventArgs.RemovedItems&lt;/a&gt; collection will be empty (have 0 items). And the only time that happens is when &lt;code&gt;ListPicker&lt;/code&gt; is transitioning from an empty list to a non-empty one (e.g., on startup). &lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ListPicker&lt;/code&gt;'s transitions between &lt;code&gt;Normal&lt;/code&gt; and &lt;code&gt;Expanded&lt;/code&gt; mode are effectively animations of the control's &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.height(VS.95).aspx"&gt;Height&lt;/a&gt;. Because &lt;code&gt;Height&lt;/code&gt; changes cause a layout pass, they don't take place on the composition thread and therefore are more susceptible to performance issues. An easy way to mitigate this in the typical "list of items in a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.stackpanel(VS.95).aspx"&gt;StackPanel&lt;/a&gt;" scenario is to add &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.cachemode(VS.95).aspx"&gt;CacheMode&lt;/a&gt;=&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.bitmapcache(v=VS.95).aspx"&gt;BitmapCache&lt;/a&gt; to the elements that appear &lt;strong&gt;below&lt;/strong&gt; the &lt;code&gt;ListPicker&lt;/code&gt; (i.e., those that are pushed down by the animation). Please refer back to the first XAML snippet for an example - this tweak allows the Silverlight layout system to animate such controls as bitmaps and that helps the animation run a bit more smoothly. &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: If you don't want to apply &lt;code&gt;BitmapCache&lt;/code&gt; to every control &lt;em&gt;individually&lt;/em&gt;, an alternate approach is to wrap the affected controls in another &lt;code&gt;StackPanel&lt;/code&gt; and set the &lt;code&gt;CacheMode&lt;/code&gt; property on the StackPanel instead. Please see the last XAML snippet above for an example of this. &lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you have a long list of controls in a &lt;code&gt;StackPanel&lt;/code&gt; inside a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer(VS.95).aspx"&gt;ScrollViewer&lt;/a&gt; and there's a &lt;code&gt;ListPicker&lt;/code&gt; near the bottom using &lt;code&gt;Expanded&lt;/code&gt; mode, that expansion does &lt;strong&gt;not&lt;/strong&gt; automatically scroll the screen to keep the &lt;code&gt;ListPicker&lt;/code&gt; completely in view. On WPF, the fix would be a simple matter of calling &lt;a href="http://msdn.microsoft.com/en-us/library/ms598110.aspx"&gt;FrameworkElement.BringIntoView&lt;/a&gt;. However, Silverlight doesn't have that API and there doesn't seem to be a good &lt;em&gt;general purpose&lt;/em&gt; way for &lt;code&gt;ListPicker&lt;/code&gt; to find the right parent to scroll. (Although walking up the visual tree to find the first &lt;code&gt;ScrollViewer&lt;/code&gt; is &lt;em&gt;probably&lt;/em&gt; right in most cases, it's not a sure thing; &lt;code&gt;ListPicker&lt;/code&gt; errs on the side of caution and doesn't try to make guesses.) In practice, the underlying issue doesn't come up very often - when it has, my suggestion has been to use the &lt;code&gt;ItemCountThreshold&lt;/code&gt; property to &lt;strong&gt;force&lt;/strong&gt; the relevant &lt;code&gt;ListPicker&lt;/code&gt; to use &lt;code&gt;Full&lt;/code&gt; mode (which doesn't expand, so it doesn't alter the parent's layout, so it doesn't have this problem). &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;ListPicker&lt;/code&gt; is a relatively straightforward control that should be familiar to anyone who's used the standard &lt;code&gt;ListBox&lt;/code&gt;. But while its API may be unremarkable, its user experience is &lt;strong&gt;all&lt;/strong&gt; Windows Phone 7 goodness! :) &lt;/p&gt;
&lt;p&gt;I hope you enjoy it! &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10085617" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight+Toolkit/">Silverlight Toolkit</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone+Toolkit/">Windows Phone Toolkit</category></item><item><title>Mo controls, mo controls, mo controls... [Announcing the second release of the Silverlight for Windows Phone Toolkit!]</title><link>http://blogs.msdn.com/b/delay/archive/2010/11/02/mo-controls-mo-controls-mo-controls-announcing-the-second-release-of-the-silverlight-for-windows-phone-toolkit.aspx</link><pubDate>Tue, 02 Nov 2010 23:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10085132</guid><dc:creator>David Anson</dc:creator><slash:comments>56</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10085132</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2010/11/02/mo-controls-mo-controls-mo-controls-announcing-the-second-release-of-the-silverlight-for-windows-phone-toolkit.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;I'm happy to report that we've just published the &lt;a href="http://silverlight.codeplex.com/releases/view/55034"&gt;Silverlight for Windows Phone Toolkit November 2010 release&lt;/a&gt;! This is the second iteration of the Windows Phone Toolkit and effectively &lt;strong&gt;doubles&lt;/strong&gt; the number of controls we've created to help developers and designers build more compelling, more platform-consistent user experiences with ease. The &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/16/pining-for-windows-phone-7-controls-we-got-ya-covered-announcing-the-first-release-of-the-silverlight-for-windows-phone-toolkit.aspx"&gt;first Windows Phone Toolkit release&lt;/a&gt; has been a big hit and we've seen a &lt;strong&gt;lot&lt;/strong&gt; of developers using it (in both binary and source forms) to build their Windows Phone 7 applications. But while we tried to address the most pressing needs with that release, there were still a couple of prominent controls missing... &lt;/p&gt;
&lt;p&gt;With today's update, we've tried to provide &lt;strong&gt;more&lt;/strong&gt; of the fundamental controls customers have been asking for - as well as API documentation and fixes for some of the bugs people reported with the first release. Recall that the Windows Phone Toolkit is published on &lt;a href="http://silverlight.codeplex.com/"&gt;CodePlex&lt;/a&gt; under the &lt;a href="http://opensource.org/licenses/ms-pl.html"&gt;Ms-PL open-source license&lt;/a&gt; so anyone who wants can look at the source code to learn how we've done things - or customize any control to suit their specific scenario. As always, if you have suggestions for things we should add or change, please search the &lt;a href="http://silverlight.codeplex.com/workitem/list/basic"&gt;CodePlex issue tracker&lt;/a&gt; and vote for the issue (or create a &lt;strong&gt;new&lt;/strong&gt; one if the idea is unique). We use your input to help prioritize our efforts and ensure we're delivering the right things for the community! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="font-size:12pt"&gt;&lt;strong&gt;What's New?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ListPicker&lt;/strong&gt;&lt;/p&gt;
&lt;img height="163" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/2100.WpTkOct10_2D00_ListPicker.png" alt="ListPicker sample" /&gt; &lt;img height="175" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/7802.WpTkOct10_2D00_ListPicker_2D00_Full.png" alt="ListPicker popup sample" /&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;ListPicker&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Header&lt;/span&gt;="background"&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;sys&lt;/span&gt;:&lt;span style="color:#a31515"&gt;String&lt;/span&gt;&amp;gt;&lt;span style="color:#a31515"&gt;dark&lt;/span&gt;&amp;lt;/&lt;span style="color:#a31515"&gt;sys&lt;/span&gt;:&lt;span style="color:#a31515"&gt;String&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;sys&lt;/span&gt;:&lt;span style="color:#a31515"&gt;String&lt;/span&gt;&amp;gt;&lt;span style="color:#a31515"&gt;light&lt;/span&gt;&amp;lt;/&lt;span style="color:#a31515"&gt;sys&lt;/span&gt;:&lt;span style="color:#a31515"&gt;String&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;sys&lt;/span&gt;:&lt;span style="color:#a31515"&gt;String&lt;/span&gt;&amp;gt;&lt;span style="color:#a31515"&gt;dazzle&lt;/span&gt;&amp;lt;/&lt;span style="color:#a31515"&gt;sys&lt;/span&gt;:&lt;span style="color:#a31515"&gt;String&lt;/span&gt;&amp;gt;
&amp;lt;/&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;ListPicker&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;ListPicker&lt;/code&gt; is the Windows Phone 7 equivalent of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.combobox(VS.95).aspx"&gt;ComboBox&lt;/a&gt; control: give it a list of items and it will show the selected one and also allow the user to pick from a list if they want to change it. The core applications on Windows Phone 7 implement &lt;strong&gt;two&lt;/strong&gt; kinds of list selection: an in-place expander for picking among five or fewer items, and a full-screen popup for picking among more. The Toolkit's &lt;code&gt;ListPicker&lt;/code&gt; control combines both experiences into one handy package by &lt;strong&gt;automatically&lt;/strong&gt; selecting the right UX based on the number of items in its list! It is a standard &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol(VS.95).aspx"&gt;ItemsControl&lt;/a&gt; subclass with all the common elements of a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector(v=VS.95).aspx"&gt;Selector&lt;/a&gt;, so the API will be familiar to just about everyone. In fact, you can take most existing &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox(VS.95).aspx"&gt;ListBox&lt;/a&gt;es and convert them to &lt;code&gt;ListPicker&lt;/code&gt;s just by changing the control name in XAML! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;LongListSelector&lt;/strong&gt;&lt;/p&gt;
&lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/2287.WpTkOct10_2D00_LongListSelector_2D00_Movies.png" alt="LongListSelector movies sample" /&gt; &lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/1033.WpTkOct10_2D00_LongListSelector_2D00_People.png" alt="LongListSelector people sample" /&gt; &lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/1614.WpTkOct10_2D00_LongListSelector_2D00_JumpList.png" alt="LongListSelector jump-list sample" /&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;LongListSelector
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;    ItemsSource&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; movies&lt;/span&gt;}"
&lt;span style="color:#ff0000"&gt;    ListHeaderTemplate&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; movieListHeader&lt;/span&gt;}"
&lt;span style="color:#ff0000"&gt;    GroupHeaderTemplate&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; movieGroupHeader&lt;/span&gt;}"
&lt;span style="color:#ff0000"&gt;    GroupFooterTemplate&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; movieGroupFooter&lt;/span&gt;}"
&lt;span style="color:#ff0000"&gt;    GroupItemTemplate&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; groupItemHeader&lt;/span&gt;}"
&lt;span style="color:#ff0000"&gt;    ItemTemplate&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; movieItemTemplate&lt;/span&gt;}"&amp;gt;
&amp;lt;/&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;LongListSelector&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;p&gt;While &lt;code&gt;ListPicker&lt;/code&gt; is about simple selection scenarios, &lt;code&gt;LongListSelector&lt;/code&gt; is about &lt;strong&gt;advanced&lt;/strong&gt; ones! Think of it as &lt;code&gt;ListBox&lt;/code&gt;++--, it has everything you expect from &lt;code&gt;ListBox&lt;/code&gt; &lt;strong&gt;plus&lt;/strong&gt; a bunch of advanced capabilities and great on-device performance &lt;strong&gt;minus&lt;/strong&gt; the levels of abstraction and generality that tend to slow &lt;code&gt;ListBox&lt;/code&gt; down. &lt;code&gt;LongListSelector&lt;/code&gt; supports full data and UI virtualization, flat lists, grouped lists (with headers!), and also implements the "jump list" header navigation UI that makes the "People" app so efficient! The theory behind &lt;code&gt;LongListSelector&lt;/code&gt; is that it should be easy to fix a poorly-performing &lt;code&gt;ListBox&lt;/code&gt; scenario by swapping in a &lt;code&gt;LongListSelector&lt;/code&gt; instead: it handles all the tricky parts &lt;strong&gt;for&lt;/strong&gt; you, so there's less to worry about and it "just works". Unless you've spent a lot of time fine-tuning your application's list behavior, you should see improved performance by switching to &lt;code&gt;LongListSelector&lt;/code&gt;! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;TransitionFrame (and Transitions)&lt;/strong&gt;&lt;/p&gt;
&lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/4341.WpTkOct10_2D00_TransitionFrame.png" alt="TransitionFrame sample" /&gt;
&lt;pre style="color:#000000"&gt;RootFrame = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#2b91af"&gt; TransitionFrame&lt;/span&gt;();&lt;/pre&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;TransitionService.NavigationInTransition&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;NavigationInTransition&lt;/span&gt;&amp;gt;
        &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;NavigationInTransition.Backward&lt;/span&gt;&amp;gt;
            &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;TurnstileTransition&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Mode&lt;/span&gt;="BackwardIn"/&amp;gt;
        &amp;lt;/&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;NavigationInTransition.Backward&lt;/span&gt;&amp;gt;
        &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;NavigationInTransition.Forward&lt;/span&gt;&amp;gt;
            &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;TurnstileTransition&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Mode&lt;/span&gt;="ForwardIn"/&amp;gt;
        &amp;lt;/&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;NavigationInTransition.Forward&lt;/span&gt;&amp;gt;
    &amp;lt;/&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;NavigationInTransition&lt;/span&gt;&amp;gt;
&amp;lt;/&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;TransitionService.NavigationInTransition&lt;/span&gt;&amp;gt;
&amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;TransitionService.NavigationOutTransition&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;NavigationOutTransition&lt;/span&gt;&amp;gt;
        &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;NavigationOutTransition.Backward&lt;/span&gt;&amp;gt;
            &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;TurnstileTransition&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Mode&lt;/span&gt;="BackwardOut"/&amp;gt;
        &amp;lt;/&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;NavigationOutTransition.Backward&lt;/span&gt;&amp;gt;
        &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;NavigationOutTransition.Forward&lt;/span&gt;&amp;gt;
            &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;TurnstileTransition&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Mode&lt;/span&gt;="ForwardOut"/&amp;gt;
        &amp;lt;/&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;NavigationOutTransition.Forward&lt;/span&gt;&amp;gt;
    &amp;lt;/&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;NavigationOutTransition&lt;/span&gt;&amp;gt;
&amp;lt;/&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;TransitionService.NavigationOutTransition&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/ff402535(v=VS.92).aspx"&gt;Windows Phone UI Guidelines&lt;/a&gt; encourage smooth, attractive page-to-page animations like the core applications show, but there has been little platform support for creating similar experiences in your own applications - until now! :) The new transition classes in the Windows Phone Toolkit aims to make it &lt;strong&gt;easy&lt;/strong&gt; for application developers to add attractive, platform-consistent transitions to their applications. All that's necessary to enable transitions for an application's pages is tweak &lt;code&gt;App.xaml.cs&lt;/code&gt; (shown above) and add a bit of XAML to each page to specify its transitions (also shown above). Everything else is done for you! &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: This release includes support for multiple flavors of the following transitions: turnstile, slide, rotate, swivel, and roll. It's also possible to implement custom transitions using the same framework! &lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;AutoCompleteBox&lt;/strong&gt;&lt;/p&gt;
&lt;img height="152" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/6011.WpTkOct10_2D00_AutoCompleteBox.png" alt="AutoCompleteBox sample" /&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;AutoCompleteBox
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;    ItemsSource&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; words&lt;/span&gt;}"/&amp;gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;AutoCompleteBox&lt;/code&gt; first appeared in the &lt;a href="http://silverlight.codeplex.com/releases/view/18804"&gt;Silverlight 2 Toolkit&lt;/a&gt;, then later graduated to the Silverlight 3 SDK. Now it's &lt;strong&gt;back&lt;/strong&gt; in the Toolkit - this time for Windows Phone 7! Because phones are about being small and quick to use, simplifying tedious tasks like text input is an important goal. Toward that end, a number of the core applications (like &lt;a href="http://www.bing.com/"&gt;Bing&lt;/a&gt; search) make use of auto-completion to &lt;strong&gt;predict&lt;/strong&gt; what the user is typing and save time by allowing them to click on the completed word instead. &lt;code&gt;AutoCompleteBox&lt;/code&gt; makes it easy to bring the &lt;strong&gt;same&lt;/strong&gt; convenience to your own applications by taking advantage of a phone-friendly implementation of this popular Silverlight control. By providing a suitable completion list (in any of a variety of ways), users are automatically prompted with the relevant matches as they start typing! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;API Documentation&lt;/strong&gt;&lt;/p&gt;
&lt;img height="282" width="392" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/2451.WpTkOct10_2D00_Chm.png" alt="CHM file example" /&gt;
&lt;p&gt;The source code for the Windows Phone Toolkit has included full &lt;a href="http://msdn.microsoft.com/en-us/library/b2s063f7.aspx"&gt;XML Documentation Comments&lt;/a&gt; from the beginning, but now we've begun generating a separate &lt;a href="http://en.wikipedia.org/wiki/Microsoft_Compiled_HTML_Help"&gt;CHM file&lt;/a&gt; with all the property/method/event comments in a single, easy-to-browse location. The documentation file is automatically installed by the Windows Phone Toolkit installer and a handy link is added to the "Silverlight for Windows Phone Toolkit" folder in the Start Menu. Because we don't have dedicated documentation writers on the Toolkit team, our documentation is a bit on the terse side - but the CHM file is still a great way to survey the Toolkit classes and get a feel for what's available. And because the sample syntax is available in &lt;strong&gt;both&lt;/strong&gt; C# and VB, everyone should be comfortable with the examples! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Bug fixes for existing controls&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The previous Toolkit release wasn't all that long ago and we've been quite busy since then, but we've still managed to squeeze in fixes for some of the more annoying bugs customers reported. That's not to say that we fixed them &lt;strong&gt;all&lt;/strong&gt; or that we had a chance to squash &lt;strong&gt;your&lt;/strong&gt; favorite bug, but we were fortunate to be able to fix a good number of customer-impacting issues and I hope everyone finds the new controls even more pleasant to use! :) &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://silverlight.codeplex.com/releases/view/55034"&gt;[Click here to download the Silverlight for Windows Phone Toolkit November 2010 release.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The screen shots and XAML shown above are &lt;strong&gt;all&lt;/strong&gt; from the sample application you can download along with the Toolkit. I encourage people to play around with the sample if they want to experiment with any of these controls (in the emulator &lt;em&gt;or&lt;/em&gt; on the device) or if they want to learn more about how these controls work. I anticipate more in-depth coverage will show up in the coming weeks (&lt;em&gt;I will be posting a detailed &lt;code&gt;ListPicker&lt;/code&gt; overview tomorrow!&lt;/em&gt;), but for now the sample application is a great &lt;strong&gt;springboard&lt;/strong&gt; to get folks started! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In closing, I'm really glad we've been able to get this second round of controls out to the community in such a short time! While there are probably still some "nice to have" controls that could be added to further round-out the Windows Phone 7 control offering, I think that what we've included in the Windows Phone Toolkit represents nearly &lt;strong&gt;all&lt;/strong&gt; the critical ones needed to unblock important scenarios. I hope people continue to enjoy their Windows Phone development experience and that the new Windows Phone Toolkit makes application development even &lt;strong&gt;easier&lt;/strong&gt;! :) &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10085132" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight+Toolkit/">Silverlight Toolkit</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone+Toolkit/">Windows Phone Toolkit</category></item><item><title>Is that a BLOB in your pocket, or are you just happy to see me? [Silverlight REST-based Azure/S3 BLOB API updated to run on Windows Phone 7!]</title><link>http://blogs.msdn.com/b/delay/archive/2010/10/12/is-that-a-blob-in-your-pocket-or-are-you-just-happy-to-see-me-silverlight-rest-based-azure-s3-blob-api-updated-to-run-on-windows-phone-7.aspx</link><pubDate>Tue, 12 Oct 2010 16:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10074840</guid><dc:creator>David Anson</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10074840</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2010/10/12/is-that-a-blob-in-your-pocket-or-are-you-just-happy-to-see-me-silverlight-rest-based-azure-s3-blob-api-updated-to-run-on-windows-phone-7.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;It was about five months ago that I blogged about &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/05/13/gettin-blobby-with-it-sharing-the-code-for-a-simple-silverlight-4-rest-based-cloud-oriented-file-management-app-for-azure-and-s3.aspx"&gt;BlobStore, a simple Silverlight 4 REST-based cloud-oriented file management app for Azure and S3&lt;/a&gt;. I pitched it like this: &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;It's a small, lightweight Silverlight 4 application that acts as a basic front-end for the &lt;a href="http://www.microsoft.com/windowsazure/windowsazure/"&gt;Windows Azure Simple Data Storage&lt;/a&gt; and the &lt;a href="http://aws.amazon.com/s3/"&gt;Amazon Simple Storage Service (S3)&lt;/a&gt;! Just run the &lt;code&gt;BlobStore&lt;/code&gt; app, point it at a properly provisioned Azure or S3 account (see below for details on provisioning), and all of a sudden sharing files with yourself and others becomes as simple as dragging and dropping them! &lt;/p&gt;
&lt;p&gt;... &lt;/p&gt;
&lt;p&gt;Included with every code download is a &lt;strong&gt;free&lt;/strong&gt; &lt;a href="http://en.wikipedia.org/wiki/Representational_State_Transfer"&gt;REST&lt;/a&gt; wrapper for basic Azure and S3 blob access that handles all the tricky &lt;a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html"&gt;Authorization&lt;/a&gt; &lt;a href="http://docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAuthentication.html"&gt;header&lt;/a&gt; &lt;a href="http://msdn.microsoft.com/en-us/library/dd179428.aspx"&gt;details&lt;/a&gt; for you. It's almost guaranteed to make your next Azure/S3 application a snap to develop and a wild success in the marketplace. &lt;/p&gt;
&lt;/blockquote&gt;
&lt;img height="479" width="602" src="http://blogs.msdn.com/blogfiles/delay/BlobStore-List.png" alt="BlobStore with silly sample data" /&gt;
&lt;p style="font-size:9px"&gt;&lt;em&gt;Disclaimer: None of the file names above is accurate.&lt;/em&gt; :) &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I know people have incorporated my REST API wrapper code (&lt;code&gt;BlobStoreApi.cs&lt;/code&gt;) into their Silverlight projects, so it wasn't too surprising when I heard that some of you want the same functionality for your Windows Phone 7 applications. While you might expect the existing code to work as-is, there's a &lt;strong&gt;catch&lt;/strong&gt;: Windows Phone 7's version of the Silverlight framework doesn't support the &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.allowwritestreambuffering(v=VS.95).aspx"&gt;HttpWebRequest.AllowWriteStreamBuffering&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.webrequest.contentlength(v=VS.95).aspx"&gt;WebRequest.ContentLength&lt;/a&gt; properties - and both are used by the original &lt;code&gt;BlobStoreApi.cs&lt;/code&gt; implementation... &lt;/p&gt;
&lt;p&gt;Fortunately, the lack of &lt;code&gt;AllowWriteStreamBuffering&lt;/code&gt; isn't a big deal because it's used in only one place and can be commented-out with no loss of functionality (assuming the default behavior of buffering the entire upload doesn't bother you). However, the lack of &lt;code&gt;ContentLength&lt;/code&gt; is a little more problematic because its use is more tightly integrated with the rest of code. So it seemed worthwhile for me to update &lt;code&gt;BlobStoreApi.cs&lt;/code&gt; for Windows Phone 7 - and it turned out to be fairly simple to remove &lt;code&gt;ContentLength&lt;/code&gt; for Windows Phone 7 &lt;strong&gt;without&lt;/strong&gt; changing the existing behavior for Silverlight 4 and desktop .NET. &lt;/p&gt;
&lt;p&gt;Because the original file management sample application didn't translate very well to the phone, I dashed off a quick "note taking" sample instead: &lt;/p&gt;
&lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/6813.BlobStoreOnWindowsPhone.png" alt="BlobStoreOnWindowsPhone sample" /&gt;
&lt;p&gt;The way the new sample works is that the user can type short notes in a text box and then hit the "add" button to upload them to their pre-configured Azure/S3 account as &lt;a href="http://en.wikipedia.org/wiki/Binary_large_object"&gt;BLOB&lt;/a&gt;s with the blob name being the current &lt;a href="http://msdn.microsoft.com/en-us/library/system.datetime.ticks(v=VS.95).aspx"&gt;DateTime.Now.Ticks&lt;/a&gt; value and its content being the text of the note. All available notes are listed by date of creation; their text contents are downloaded on demand and shown to the user when selected. Any note can be deleted by tapping it and hitting the "delete" button. &lt;/p&gt;
&lt;p&gt;It's a simple application, but it shows off the list/get/put/delete functionality that &lt;code&gt;BlobStoreApi&lt;/code&gt; implements for Azure, S3, and &lt;a href="http://msdn.microsoft.com/en-us/library/3ak841sy(v=VS.95).aspx"&gt;IsolatedStorage&lt;/a&gt; (the last existing mainly for test purposes). During calls to the BLOB service, the sample application shows a simple progress screen informing the user of the ongoing transaction. (Of course, IsolatedStorage is &lt;strong&gt;very&lt;/strong&gt; fast, so the progress screen is little more than a flicker by default - it's more meaningful for Azure/S3 web access.) &lt;/p&gt;
&lt;p&gt;The complete implementation can be found in &lt;code&gt;BlobStore\BlobStoreApi.cs&lt;/code&gt; and compiles/runs on the .NET, Silverlight, and Windows Phone 7 platforms. I encourage readers to use this code to create &lt;strong&gt;way&lt;/strong&gt; more compelling applications than my samples! :) &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/BlobStore/BlobStore.zip"&gt;[Click here to download the complete BlobStore source code and sample applications for both Silverlight 4 and Windows Phone 7.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Note:&lt;/strong&gt; By default, the Windows Phone sample uses IsolatedStorage because I don't want to publish the keys to my Azure/S3 accounts. :) If you want to try it with your own account(s), just open &lt;code&gt;MainPage.xaml.cs&lt;/code&gt;, uncomment the relevant line below, and add the missing information:
&lt;pre style="color:#008000;font-size:8pt"&gt;// TODO: Switch to AzureBlobStoreClient or S3BlobStoreClient after entering your connection information
&lt;span style="color:#0000ff"&gt;private readonly&lt;/span&gt;&lt;span style="color:#000000"&gt; BlobStoreClient _client = &lt;/span&gt;&lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#000000"&gt; IsolatedStorageBlobStoreClient();
&lt;/span&gt;//private readonly BlobStoreClient _client = new AzureBlobStoreClient("Account Name", "Access Key");
//private readonly BlobStoreClient _client = new S3BlobStoreClient("Access Key ID", "Secret Access Key", "Bucket Name");&lt;/pre&gt;
&lt;strong&gt;Aside&lt;/strong&gt;: Don't forget to provision your account first; &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/05/13/gettin-blobby-with-it-sharing-the-code-for-a-simple-silverlight-4-rest-based-cloud-oriented-file-management-app-for-azure-and-s3.aspx"&gt;see the notes here for more information&lt;/a&gt;! &lt;/blockquote&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10074840" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/WPF/">WPF</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category></item><item><title>There's no substitute for customer feedback! [Improving Windows Phone 7 application performance now a bit easier with LowProfileImageLoader and DeferredLoadListBox updates]</title><link>http://blogs.msdn.com/b/delay/archive/2010/10/04/there-s-no-substitute-for-customer-feedback-improving-windows-phone-7-application-performance-now-a-bit-easier-with-lowprofileimageloader-and-deferredloadlistbox-updates.aspx</link><pubDate>Mon, 04 Oct 2010 16:55:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10071262</guid><dc:creator>David Anson</dc:creator><slash:comments>20</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10071262</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2010/10/04/there-s-no-substitute-for-customer-feedback-improving-windows-phone-7-application-performance-now-a-bit-easier-with-lowprofileimageloader-and-deferredloadlistbox-updates.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;&lt;img height="554" width="305" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/6404.PhonePerformance_2D00_ListScrolling.png" alt="PhonePerformance List Scrolling sample" style="float:right" /&gt; Windows Phone 7 applications run on hardware that's considerably less powerful than what drives typical desktop and laptop machines. Therefore, tuning phone applications for optimum performance is an important task - and a challenging one! To help other developers, I previously coded and blogged about two classes: &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/02/keep-a-low-profile-lowprofileimageloader-helps-the-windows-phone-7-ui-thread-stay-responsive-by-loading-images-in-the-background.aspx"&gt;LowProfileImageLoader (pushes much of the cost of loading images off the UI thread)&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/08/never-do-today-what-you-can-put-off-till-tomorrow-deferredloadlistbox-and-stackpanel-help-windows-phone-7-lists-scroll-smoothly-and-consistently.aspx"&gt;DeferredLoadListBox (improves the scrolling experience for long lists)&lt;/a&gt;. These two classes can be used individually or together and have become a regular part of the recommendations for developers experiencing performance issues. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I've heard from lots of people who've benefitted from &lt;code&gt;LowProfileImageLoader&lt;/code&gt; and &lt;code&gt;DeferredLoadListBox&lt;/code&gt; - thank you! I've also received some great suggestions; I recently implemented some of them and wanted to share the new code/bits: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The first issue was reported to me by &lt;a href="http://blogs.ugidotnet.org/corrado/"&gt;Corrado Cavalli&lt;/a&gt; via email. Whereas my sample applications loaded data after they'd initialized, Corrado's &lt;code&gt;DeferredLoadListBox&lt;/code&gt; scenario populated its data &lt;strong&gt;during&lt;/strong&gt; initialization. This led to code running in &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.onapplytemplate(VS.95).aspx"&gt;OnApplyTemplate&lt;/a&gt; which made the (wrong) assumption that the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.listbox(VS.95).aspx"&gt;ListBox&lt;/a&gt;'s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.listboxitem(VS.95).aspx"&gt;ListBoxItem&lt;/a&gt; containers would already have been created. That's not the case during &lt;code&gt;OnApplyTemplate&lt;/code&gt;, so &lt;code&gt;DeferredLoadListBox&lt;/code&gt; got confused and threw an exception. The simple fix for this problem is to allow for missing containers during &lt;code&gt;OnApplyTemplate&lt;/code&gt; - which I've done. Fortunately, subsequent activity (container creation during &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.preparecontainerforitemoverride(v=VS.95).aspx"&gt;PrepareContainerForItemOverride&lt;/a&gt;) already ensures the right things happen after the containers are created. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The second issue was reported to me by &lt;a href="http://www.munkiisoft.com/blog/"&gt;Pat Long&lt;/a&gt; in &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/02/keep-a-low-profile-lowprofileimageloader-helps-the-windows-phone-7-ui-thread-stay-responsive-by-loading-images-in-the-background.aspx#comments"&gt;the comments to my first blog post&lt;/a&gt;. The problem he encountered was that Blend would crash when working with an application using &lt;code&gt;LowProfileImageLoader&lt;/code&gt; in certain cases (presumably because of the background worker thread it creates). There's an easy fix here as well - simply short-circuit the worker thread at design-time because the performance implications of &lt;code&gt;LowProfileImageLoader&lt;/code&gt; aren't relevant then anyway. I reproduced the problem myself with Visual Studio and fixed it there - then I checked Pat's blog and found he'd done almost &lt;strong&gt;exactly&lt;/strong&gt; the same thing for his Blend-based scenario! [It's nice when separate efforts arrive at the same place. :) ] &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The third suggestion also came from &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/02/keep-a-low-profile-lowprofileimageloader-helps-the-windows-phone-7-ui-thread-stay-responsive-by-loading-images-in-the-background.aspx#comments"&gt;comments to that blog post&lt;/a&gt; - &lt;a href="http://davidburela.wordpress.com/"&gt;David Burela&lt;/a&gt; wanted to use &lt;code&gt;LowProfileImageLoader&lt;/code&gt; for images that were part of his application. I'd only been considering the cost of &lt;strong&gt;downloading&lt;/strong&gt; images when I wrote this class, but David pointed out that much of the same "UI thread-friendly" logic should apply to &lt;strong&gt;local&lt;/strong&gt; images as well. Fortunately, it was a simple matter to add support for relative &lt;a href="http://msdn.microsoft.com/en-us/library/system.uri(VS.95).aspx"&gt;Uri&lt;/a&gt;s (ex: "/Images/Picture.jpg") - and now &lt;code&gt;LowProfileImageLoader&lt;/code&gt; works well with both kinds of images! &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Note&lt;/strong&gt;: For this new functionality to work, the project's images must have their "Build Action" set to "Content" (not "Resource"). (&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/3301.WpTkSep10_2D00_IconConfiguration.png"&gt;Here's what that setting looks like in Visual Studio.&lt;/a&gt;) &lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The fourth suggestion came from &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/08/never-do-today-what-you-can-put-off-till-tomorrow-deferredloadlistbox-and-stackpanel-help-windows-phone-7-lists-scroll-smoothly-and-consistently.aspx#comments"&gt;the comments to my second blog post&lt;/a&gt; where &lt;strong&gt;Johnny Westlake&lt;/strong&gt; pointed out that &lt;code&gt;LowProfileImageLoader&lt;/code&gt; could be counterproductive once it had already worked its magic. In other words, though it's great for lowering the cost of &lt;strong&gt;initial&lt;/strong&gt; image load, the throttling behavior might be undesirable during &lt;strong&gt;subsequent&lt;/strong&gt; loads (ex: during Back button navigation) because by that time the image has been cached by the web stack and the download cost is much lower. At first, I wasn't sure how &lt;code&gt;LowProfileImageLoader&lt;/code&gt; could tell which situation a particular image was in - then I realized I didn't have to! :) &lt;/p&gt;
&lt;p&gt;What I've done instead is add a static &lt;code&gt;LowProfileImageLoader.IsEnabled&lt;/code&gt; property (&lt;code&gt;true&lt;/code&gt; by default) that the &lt;strong&gt;developer&lt;/strong&gt; can toggle whenever he/she wants to (ex: on Back navigation to a page that has already used &lt;code&gt;LowProfileImageLoader&lt;/code&gt;). When this property is set to &lt;code&gt;false&lt;/code&gt;, &lt;code&gt;LowProfileImageLoader&lt;/code&gt; doesn't perform its UI thread sleight-of-hand so the image load behavior is the same as it would have been if &lt;code&gt;LowProfileImageLoader&lt;/code&gt; weren't present at all. While this might seem like a bit of a &lt;a href="http://en.wikipedia.org/wiki/Buck_passing"&gt;pass the buck&lt;/a&gt; move on my part, the practical truth is that the application's author has &lt;strong&gt;way&lt;/strong&gt; more context than &lt;code&gt;LowProfileImageLoader&lt;/code&gt; does. So in lieu of a reliable way to detect the cache state of individual images (&lt;em&gt;I'm open to suggestions, by the way!&lt;/em&gt;), the new &lt;code&gt;IsEnabled&lt;/code&gt; property seems like a reasonable "next best thing". &lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/PhonePerformance/PhonePerformance.zip"&gt;[Click here to download the compiled PhonePerformance assembly, sample applications, and full source code for everything.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My thanks go out to the people who have shared their experience and suggestions with/for &lt;code&gt;LowProfileImageLoader&lt;/code&gt; and &lt;code&gt;DeferredLoadListBox&lt;/code&gt;! While these two classes are not appropriate in &lt;strong&gt;every&lt;/strong&gt; situation, they seem to be useful in &lt;strong&gt;enough&lt;/strong&gt; situations that it's worth giving them a quick try if you're experiencing relevant performance problems. Both classes are easy to hook up, so trying them out takes no more than a couple of minutes - which will be time well spent if the problem goes away! &lt;/p&gt;
&lt;p&gt;I wish everyone good luck with their Windows Phone 7 applications - and please don't forget the value of great performance! :) &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10071262" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category></item><item><title>This one's for you, Gregor Mendel [Code to animate and fade Windows Phone orientation changes now supports a new mode: hybrid!]</title><link>http://blogs.msdn.com/b/delay/archive/2010/09/28/this-one-s-for-you-gregor-mendel-code-to-animate-and-fade-windows-phone-orientation-changes-now-supports-a-new-mode-hybrid.aspx</link><pubDate>Tue, 28 Sep 2010 16:34:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10068826</guid><dc:creator>David Anson</dc:creator><slash:comments>8</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10068826</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2010/09/28/this-one-s-for-you-gregor-mendel-code-to-animate-and-fade-windows-phone-orientation-changes-now-supports-a-new-mode-hybrid.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;This isn't my first time discussing &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/05/27/you-spin-me-round-like-a-record-easily-animate-orientation-changes-for-any-windows-phone-application-with-this-handy-source-code.aspx"&gt;animating&lt;/a&gt; &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/07/13/spin-spin-sugar-updated-code-to-easily-animate-orientation-changes-for-any-windows-phone-application.aspx"&gt;device&lt;/a&gt; &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/08/18/fade-into-you-code-to-easily-animate-orientation-changes-for-windows-phone-applications-now-supports-fade-too.aspx"&gt;orientation&lt;/a&gt; &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/13/he-has-a-right-to-criticize-who-has-a-heart-to-help-two-fixes-for-dynamicorientationchanges-improve-the-experience-of-animating-and-fading-windows-phone-orientation-changes.aspx"&gt;changes&lt;/a&gt;, so I won't spend a lot of time explaining the motivation. Here's where things left off last time: &lt;/p&gt;
&lt;blockquote&gt;For "in your face" transitions, there's &lt;code&gt;AnimateOrientationChangesFrame&lt;/code&gt; which animates the rotation interactively (but might get bogged down by complex layouts). For more subtle transitions that perform smoothly &lt;strong&gt;regardless&lt;/strong&gt; of how complex the page layout is, there's &lt;code&gt;FadeOrientationChangesFrame&lt;/code&gt; which fades between the before/after layouts. Both classes have the same API and both are used in the same manner - it's just a matter of choosing the right one for &lt;strong&gt;your&lt;/strong&gt; scenario. &lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The purpose of this post is to announce a &lt;strong&gt;new&lt;/strong&gt; class, &lt;code&gt;HybridOrientationChangesFrame&lt;/code&gt;, which is meant to combine the best parts of the two existing classes! &lt;/p&gt;
&lt;img height="300" width="551" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/6136.DynamicOrientationChanges_2D00_Hybrid.png" alt="HybridOrientationChanges sample" /&gt;
&lt;p&gt;By coincidence, &lt;a href="http://kodierer.blogspot.com/"&gt;Ren&amp;eacute; Schulte&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/steve_starcks_blog/"&gt;Steve Starck&lt;/a&gt; independently contacted me last week to ask about implementing something that unified &lt;code&gt;AnimateOrientationChangesFrame&lt;/code&gt; and &lt;code&gt;FadeOrientationChangesFrame&lt;/code&gt;: code that animated the rotation between the "before" and "after" states - but faded between them instead of morphing from one shape into the other. The idea behind their request is to get some of the same "&lt;em&gt;Ooh, the application is turning!&lt;/em&gt;" visual appeal of &lt;code&gt;AnimateOrientationChangesFrame&lt;/code&gt; &lt;strong&gt;without&lt;/strong&gt; the undesirable performance implications for complex layouts. Because the "before" and "after" states don't change size in the proposed scenario, the entire animation can be done on the composition (render) thread! This same visual effect is implemented by some of the core Windows Phone 7 applications - so now it's easy to match that effect in your &lt;strong&gt;own&lt;/strong&gt; applications with &lt;code&gt;HybridOrientationChangesFrame&lt;/code&gt;! &lt;/p&gt;
&lt;p&gt;While all three of my classes continue to share the same API, the implementation of &lt;code&gt;HybridOrientationChangesFrame&lt;/code&gt; is much closer to &lt;code&gt;FadeOrientationChangesFrame&lt;/code&gt; than &lt;code&gt;AnimateOrientationChangesFrame&lt;/code&gt;. The main difference is that &lt;code&gt;HybridOrientationChangesFrame&lt;/code&gt; runs &lt;strong&gt;four&lt;/strong&gt; simultaneous &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.animation.timeline(v=VS.95).aspx"&gt;Timeline&lt;/a&gt;s instead of just one. However, that's not a cause for concern because they're all part of the same &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.animation.storyboard(v=VS.95).aspx"&gt;Storyboard&lt;/a&gt; and the right kind to run on the composition thread (specifically: &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.animation.doubleanimation(VS.95).aspx"&gt;DoubleAnimation&lt;/a&gt;s of &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.opacity(VS.95).aspx"&gt;UIElement.Opacity&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.rotatetransform.angle(v=VS.95).aspx"&gt;RotateTransform.Angle&lt;/a&gt;). So although there's a little more activity going on here, there's no need to run expensive (UI thread-bound) layout passes or anything like that. Consequently, &lt;code&gt;HybridOrientationChangesFrame&lt;/code&gt; (just like &lt;code&gt;FadeOrientationChangesFrame&lt;/code&gt;) should run smoothly even for applications with &lt;strong&gt;complex&lt;/strong&gt; page layouts. &lt;/p&gt;
&lt;p&gt;It's good to have choices in life - and now you have 50% &lt;strong&gt;more&lt;/strong&gt; choice when it comes to handling Windows Phone 7 orientation changes! :) &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/DynamicOrientationChanges/DynamicOrientationChanges.zip"&gt;[Click here to download the DynamicOrientationChanges sample and pre-compiled assembly for the Windows Phone 7 platform.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;img height="300" width="551" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/4762.DynamicOrientationChanges_2D00_Fade.png" alt="FadeOrientationChanges sample" /&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The steps for adding a rotation/fade/hybrid animation to a new application remain the same: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Enable support for orientation changes by making the following change to the XAML for the relevant &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.phoneapplicationpage(v=VS.92).aspx"&gt;PhoneApplicationPage&lt;/a&gt;s (note that rotation is &lt;strong&gt;not&lt;/strong&gt; enabled by default for new pages): &lt;span style="text-decoration: line-through;"&gt;
&lt;pre style="color:#ff0000"&gt;SupportedOrientations&lt;span style="color:#0000ff"&gt;="Portrait"&lt;/span&gt;&lt;/pre&gt;
&lt;/span&gt;
&lt;pre style="color:#ff0000"&gt;SupportedOrientations&lt;span style="color:#0000ff"&gt;="PortraitOrLandscape"&lt;/span&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;Verify (by running in the emulator or on the device) the pages you expect to support rotation really do - if things aren't rotating at this point, trying to animate the rotations won't help. &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add the &lt;code&gt;AnimateOrientationChangesFrame.cs&lt;/code&gt; or &lt;code&gt;FadeOrientationChangesFrame.cs&lt;/code&gt; or &lt;code&gt;HybridOrientationChangesFrame.cs&lt;/code&gt; source code file from the sample to your project/solution. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;-OR-&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Add a reference to the pre-compiled &lt;code&gt;DynamicOrientationChanges.dll&lt;/code&gt; assembly from the sample download to your project/solution. &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Open &lt;code&gt;App.xaml.cs&lt;/code&gt; and change the &lt;code&gt;RootFrame&lt;/code&gt; initialization in the &lt;code&gt;InitializePhoneApplication&lt;/code&gt; method (you may need to expand the &lt;code&gt;Phone application initialization&lt;/code&gt; region at the bottom): &lt;span style="text-decoration: line-through;"&gt;
&lt;pre style="color:#000000"&gt;RootFrame = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="color:#2b91af"&gt; PhoneApplicationFrame&lt;/span&gt;();&lt;/pre&gt;
&lt;/span&gt;
&lt;pre style="color:#000000"&gt;RootFrame = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; Delay.&lt;span style="color:#2b91af"&gt;AnimateOrientationChangesFrame&lt;/span&gt;();&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;-OR-&lt;/strong&gt;&lt;/p&gt;
&lt;pre style="color:#000000"&gt;RootFrame = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; Delay.&lt;span style="color:#2b91af"&gt;FadeOrientationChangesFrame&lt;/span&gt;();&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;-OR-&lt;/strong&gt;&lt;/p&gt;
&lt;pre style="color:#000000"&gt;RootFrame = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; Delay.&lt;span style="color:#2b91af"&gt;HybridOrientationChangesFrame&lt;/span&gt;();&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Done&lt;/strong&gt;; rotations will now be animated! To customize the animation, use the &lt;code&gt;Duration&lt;/code&gt;, &lt;code&gt;EasingFunction&lt;/code&gt;, and &lt;code&gt;IsAnimationEnabled&lt;/code&gt; properties which are all present and continue to work as outlined in the &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/05/27/you-spin-me-round-like-a-record-easily-animate-orientation-changes-for-any-windows-phone-application-with-this-handy-source-code.aspx"&gt;original post&lt;/a&gt;. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;img height="305" width="554" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/7411.DynamicOrientationChanges_2D00_Animate.png" alt="AnimateOrientationChanges sample" /&gt; &lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10068826" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category></item><item><title>Teaching an old dog new tricks [Updated HtmlTextBlock implementation uses RichTextBox to support images and hyperlinks]</title><link>http://blogs.msdn.com/b/delay/archive/2010/09/24/teaching-an-old-dog-new-tricks-updated-htmltextblock-implementation-uses-richtextbox-to-support-images-and-hyperlinks.aspx</link><pubDate>Fri, 24 Sep 2010 16:26:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10067394</guid><dc:creator>David Anson</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10067394</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2010/09/24/teaching-an-old-dog-new-tricks-updated-htmltextblock-implementation-uses-richtextbox-to-support-images-and-hyperlinks.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;&lt;a href="http://www.bing.com/search?q=HtmlTextBlock+site%3Ablogs.msdn.com%2Fb%2Fdelay"&gt;&lt;code&gt;HtmlTextBlock&lt;/code&gt; is a control I wrote &lt;strong&gt;way&lt;/strong&gt; back in 2007&lt;/a&gt; to enable the display of simple &lt;a href="http://en.wikipedia.org/wiki/Html"&gt;HTML&lt;/a&gt; markup by the Silverlight (1.1 Alpha!) platform without needing to translate it to &lt;a href="http://en.wikipedia.org/wiki/Xaml"&gt;XAML&lt;/a&gt; first. &lt;code&gt;HtmlTextBlock&lt;/code&gt; was intended more as a proof-of-concept than anything else, but it seems to have satisfied a fairly common customer need and I've heard from &lt;strong&gt;lots&lt;/strong&gt; of customers who are using it! But my last update was in 2008 and I'd kind of forgotten about this project since then... &lt;/p&gt;
&lt;p&gt;Until - out of the blue - &lt;a href="http://www.sharpgis.net/"&gt;Morten Nielsen&lt;/a&gt; (&lt;a href="http://twitter.com/SharpGIS"&gt;@SharpGIS&lt;/a&gt;) contacted me a few days ago to let me know about an update he'd done to &lt;code&gt;HtmlTextBlock&lt;/code&gt; to use Silverlight 4's &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox(VS.95).aspx"&gt;RichTextBox&lt;/a&gt; to address some of the limitations &lt;code&gt;HtmlTextBlock&lt;/code&gt; had by virtue of its very simple beginnings. I don't want to steal his thunder, so please &lt;a href="http://www.sharpgis.net/post/2010/09/15/Displaying-HTML-in-Silverlight.aspx"&gt;have a look at Morten's post for the details and the new download&lt;/a&gt;! &lt;/p&gt;
&lt;p&gt;Thanks a lot, Morten! :) &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10067394" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category></item><item><title>There are lots of ways to ask for a date [Creating custom DatePicker/TimePicker experiences is easy with the Windows Phone Toolkit]</title><link>http://blogs.msdn.com/b/delay/archive/2010/09/21/there-are-lots-of-ways-to-ask-for-a-date-creating-custom-datepicker-timepicker-experiences-is-easy-with-the-windows-phone-toolkit.aspx</link><pubDate>Tue, 21 Sep 2010 17:26:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10065769</guid><dc:creator>David Anson</dc:creator><slash:comments>38</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10065769</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2010/09/21/there-are-lots-of-ways-to-ask-for-a-date-creating-custom-datepicker-timepicker-experiences-is-easy-with-the-windows-phone-toolkit.aspx#comments</comments><description>&lt;div sizset="0" sizcache="6" class="delay"&gt;&lt;img height="200" width="120" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/8508.WpTkSep10_2D00_DatePickerPage.png" alt="DatePicker and TimePicker sample picker" style="float:right;margin-left:10px" /&gt;
&lt;p&gt;In my &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/16/pining-for-windows-phone-7-controls-we-got-ya-covered-announcing-the-first-release-of-the-silverlight-for-windows-phone-toolkit.aspx"&gt;previous post announcing the release of the Windows Phone Toolkit&lt;/a&gt;, I explained the motivation for the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.phoneapplicationpage(VS.92).aspx"&gt;PhoneApplicationPage&lt;/a&gt;-based design of the &lt;code&gt;DatePicker&lt;/code&gt; and &lt;code&gt;TimePicker&lt;/code&gt; controls. Though justified, the current implementation is fairly unusual and has the potential to trip people up if they're not ready for it. So I &lt;strong&gt;highly&lt;/strong&gt; recommend reading &lt;a href="http://blogs.msdn.com/b/delay/archive/2010/09/16/pining-for-windows-phone-7-controls-we-got-ya-covered-announcing-the-first-release-of-the-silverlight-for-windows-phone-toolkit.aspx"&gt;the details at the end of that post&lt;/a&gt; if you're using &lt;code&gt;DatePicker&lt;/code&gt; or &lt;code&gt;TimePicker&lt;/code&gt;. &lt;/p&gt;
&lt;p&gt;&lt;em&gt;[Waits patiently...] &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Okay, if you read the notes, then you understand what we've done and why. And while I'm happy to discuss the pros and cons of the current implementation, that's what we've got for now and I'm going to spend a little time highlighting its &lt;strong&gt;extensibility&lt;/strong&gt;! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As with the rest of the Phone Toolkit, our primary goal was to make it easy for developers to &lt;strong&gt;match&lt;/strong&gt; the core Windows Phone 7 experience in their own applications. Toward that end, adding an instance of &lt;code&gt;DatePicker&lt;/code&gt; or &lt;code&gt;TimePicker&lt;/code&gt; to a page gives the same "small button expands to full-page date/time picker with infinite scrolly thingies" experience that's found in the core Settings, Calendar, and Alarms applications. But sometimes you want to do things a little differently, and maybe you've got a date/time picking interface in mind that's more relevant to &lt;strong&gt;your&lt;/strong&gt; scenario... &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote sizset="0" sizcache="6"&gt;
&lt;p&gt;&lt;strong&gt;Aside&lt;/strong&gt;: If what you want to do is change the format used to display the date/time on the face of the initial "button", then all you need to do is set the &lt;code&gt;ValueStringFormat&lt;/code&gt; property to the &lt;a href="http://msdn.microsoft.com/en-us/library/az4se3k1(v=VS.95).aspx"&gt;standard date and time format string&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=VS.95).aspx"&gt;custom date and time format string&lt;/a&gt; of your choice! &lt;/p&gt;
&lt;p&gt;But because format strings include "{" and "}", they're a little tricky to code in XAML; you need to &lt;a href="http://en.wikipedia.org/wiki/Escape_character"&gt;escape&lt;/a&gt; the special characters. here's an example of what this looks like in its simplest form: &lt;span style="color:#ff0000"&gt;ValueStringFormat&lt;span style="color:#0000ff"&gt;="{}{0:d}"&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;And here are a few practical examples (using the culture settings for USA): &lt;/p&gt;
&lt;table border="1"&gt;
&lt;thead style="font-weight:bold"&gt;
&lt;tr&gt;
&lt;td&gt;Description&lt;/td&gt;
&lt;td&gt;XAML&lt;/td&gt;
&lt;td&gt;Sample&lt;/td&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Short date format (&lt;code&gt;DatePicker&lt;/code&gt; default)&lt;/td&gt;
&lt;td&gt;&lt;span style="color:#0000ff"&gt;"{}{0:d}"&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;9/20/2010&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Short time format (&lt;code&gt;TimePicker&lt;/code&gt; default)&lt;/td&gt;
&lt;td&gt;&lt;span style="color:#0000ff"&gt;"{}{0:t}"&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;4:00 PM&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Long date format&lt;/td&gt;
&lt;td&gt;&lt;span style="color:#0000ff"&gt;"{}{0:D}"&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;Monday, September 20, 2010&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Long time format&lt;/td&gt;
&lt;td&gt;&lt;span style="color:#0000ff"&gt;"{}{0:T}"&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;4:00:00 PM&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Explicit month/day/year format&lt;/td&gt;
&lt;td&gt;&lt;span style="color:#0000ff"&gt;"{}{0:MM-dd-yyyy}"&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;09-20-2010&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Explicit 24-hour time format with text&lt;/td&gt;
&lt;td&gt;&lt;span style="color:#0000ff"&gt;"{}The 24-hour time is {0:HH:mm}."&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;The 24-hour time is 16:00.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Customizing the full-screen picker page is as simple as setting the &lt;code&gt;DatePicker.PickerPageUri&lt;/code&gt; or &lt;code&gt;TimePicker.PickerPageUri&lt;/code&gt; property to point to a &lt;code&gt;PhoneApplicationPage&lt;/code&gt; that implements the &lt;code&gt;IDateTimePickerPage&lt;/code&gt; interface. The &lt;code&gt;PickerPageUri&lt;/code&gt; property uses the standard &lt;a href="http://msdn.microsoft.com/library/cc296240(VS.95).aspx"&gt;assembly-relative syntax ("/assemblyShortName;component/resourceLocation")&lt;/a&gt;, so it should be familiar to most folks. The &lt;code&gt;IDateTimePickerPage&lt;/code&gt; interface is a new interface, but I think you'll agree it's pretty basic: &lt;/p&gt;
&lt;pre style="color:#000000"&gt;&lt;span style="color:#0000ff"&gt;namespace&lt;/span&gt; Microsoft.Phone.Controls.Primitives
{
    &lt;span style="color:#808080"&gt;/// &amp;lt;summary&amp;gt;
    ///&lt;/span&gt;&lt;span style="color:#008000"&gt; Represents an interface for DatePicker/TimePicker to use for communicating with a picker page.&lt;/span&gt;&lt;span style="color:#808080"&gt;
    /// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;
    public interface&lt;/span&gt;&lt;span style="color:#2b91af"&gt; IDateTimePickerPage&lt;/span&gt;
    {
        &lt;span style="color:#808080"&gt;/// &amp;lt;summary&amp;gt;
        ///&lt;/span&gt;&lt;span style="color:#008000"&gt; Gets or sets the DateTime to show in the picker page and to set when the user makes a selection.&lt;/span&gt;&lt;span style="color:#808080"&gt;
        /// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;span style="color:#2b91af"&gt;
        DateTime&lt;/span&gt;? Value { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }
    }
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When it's time to display the picker page, &lt;code&gt;DatePicker&lt;/code&gt; and &lt;code&gt;TimePicker&lt;/code&gt; navigate to the page specified by &lt;code&gt;PickerPageUri&lt;/code&gt; via the &lt;a href="http://msdn.microsoft.com/en-us/library/ms591053(v=VS.92).aspx"&gt;NavigationService.Navigate("...")&lt;/a&gt; method, wait for the page to load, get a reference to its &lt;code&gt;IDateTimePickerPage&lt;/code&gt; interface, and set its &lt;code&gt;Value&lt;/code&gt; property to the starting &lt;a href="http://msdn.microsoft.com/en-us/library/system.datetime(v=VS.95).aspx"&gt;DateTime&lt;/a&gt;. After that, the custom picker page is in complete control and can display any UI it wants. When the custom picker is done (either because the user picked a date/time or because the user cancelled the operation), the picker should set its &lt;code&gt;Value&lt;/code&gt; property to the selected date/time (or &lt;code&gt;null&lt;/code&gt; if cancelled) and then call &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.navigation.navigationservice.goback(v=VS.92).aspx"&gt;NavigationService.GoBack&lt;/a&gt; to return to the previous page. &lt;code&gt;DatePicker&lt;/code&gt; and &lt;code&gt;TimePicker&lt;/code&gt; automatically detect this, update their own &lt;code&gt;Value&lt;/code&gt; property (which automatically updates their UI), and fire their &lt;code&gt;ValueChanged&lt;/code&gt; event. &lt;/p&gt;
&lt;p&gt;In some ways, it's actually kind of &lt;strong&gt;elegant&lt;/strong&gt;! &lt;nobr&gt;:)&lt;/nobr&gt; And the fact that the picker is entirely implemented by its own &lt;code&gt;PhoneApplicationPage&lt;/code&gt; makes it really easy to work with at design-time in Visual Studio and Blend. &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To help illustrate the process, I created a sample application that uses custom pickers for &lt;code&gt;DatePicker&lt;/code&gt; and &lt;code&gt;TimePicker&lt;/code&gt; which let the user pick times &lt;strong&gt;relative&lt;/strong&gt; to the current time: &lt;/p&gt;
&lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/8117.CustomDateTimePickerPage_2D00_Sample.png" alt="CustomDateTimePickerPage sample application" /&gt; &lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/6052.CustomDateTimePickerPage_2D00_DatePicker.png" alt="Custom DatePickerPage example" /&gt; &lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/1754.CustomDateTimePickerPage_2D00_TimePicker.png" alt="Custom TimePickerPage example" /&gt;
&lt;p&gt;&lt;em&gt;The sample application shows the current date and time because what the emulator reports isn't always the same as what the host operating system reports! In my experience, it's often an hour or more off - so please keep in mind that the times used by the sample are relative to &lt;strong&gt;emulator&lt;/strong&gt; time! &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here's the XAML for the main page that hosts the &lt;code&gt;DatePicker&lt;/code&gt; and &lt;code&gt;TimePicker&lt;/code&gt; controls: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;DatePicker&lt;/span&gt;&lt;span style="color:#ff0000"&gt;
    Value&lt;/span&gt;="10/10/2010"&lt;span style="color:#ff0000"&gt;
    Header&lt;/span&gt;="Custom Date Picker Page"&lt;span style="color:#ff0000"&gt;
    PickerPageUri&lt;/span&gt;="/CustomDateTimePickerPage;component/CustomDatePickerPage.xaml"/&amp;gt;

&amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;TimePicker&lt;/span&gt;&lt;span style="color:#ff0000"&gt;
    Value&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;x&lt;/span&gt;:&lt;span style="color:#a31515"&gt;Null&lt;/span&gt;}"&lt;span style="color:#ff0000"&gt;
    Header&lt;/span&gt;="Custom Time Picker Page"&lt;span style="color:#ff0000"&gt;
    PickerPageUri&lt;/span&gt;="/CustomDateTimePickerPage;component/CustomTimePickerPage.xaml"/&amp;gt;&lt;/pre&gt;
&lt;blockquote&gt;&lt;strong&gt;Aside&lt;/strong&gt;: Just for fun, I've explicitly set the &lt;code&gt;Value&lt;/code&gt; properties here. Although the controls' default behavior of using the current date/time is likely to be what you want &lt;strong&gt;most&lt;/strong&gt; of the time, applications are free to override the initial date/time (as &lt;code&gt;DatePicker&lt;/code&gt; does above) or to provide a blank starting value (as &lt;code&gt;TimePicker&lt;/code&gt; does with the &lt;a href="http://msdn.microsoft.com/en-us/library/ms743649.aspx"&gt;x:Null markup extension&lt;/a&gt;). &lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The implementation of the custom &lt;code&gt;PhoneApplicationPage&lt;/code&gt; implementation is so basic, I'm going to show the &lt;strong&gt;complete&lt;/strong&gt; date picker here! (The custom time picker implementation is nearly identical.) I've &lt;span style="background-color:yellow"&gt;highlighted&lt;/span&gt; the particularly interesting bits, but by now they should be familiar. &lt;/p&gt;
&lt;p&gt;First the XAML, then the code: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;phone&lt;/span&gt;:&lt;span style="color:#a31515"&gt;PhoneApplicationPage&lt;/span&gt;&lt;span style="color:#ff0000"&gt;
    x&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;Class&lt;/span&gt;="CustomDateTimePickerPage.CustomDatePickerPage"&lt;span style="color:#ff0000"&gt;
    xmlns&lt;/span&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;span style="color:#ff0000"&gt;
    xmlns&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;x&lt;/span&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;span style="color:#ff0000"&gt;
    xmlns&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;phone&lt;/span&gt;="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"&lt;span style="color:#ff0000"&gt;
    xmlns&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;d&lt;/span&gt;="http://schemas.microsoft.com/expression/blend/2008"&lt;span style="color:#ff0000"&gt;
    xmlns&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;mc&lt;/span&gt;="http://schemas.openxmlformats.org/markup-compatibility/2006"&lt;span style="color:#ff0000"&gt;
    FontFamily&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; PhoneFontFamilyNormal&lt;/span&gt;}"&lt;span style="color:#ff0000"&gt;
    FontSize&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; PhoneFontSizeNormal&lt;/span&gt;}"&lt;span style="color:#ff0000"&gt;
    Foreground&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; PhoneForegroundBrush&lt;/span&gt;}"&lt;span style="color:#ff0000"&gt;
    SupportedOrientations&lt;/span&gt;="PortraitOrLandscape"&lt;span style="color:#ff0000"&gt; Orientation&lt;/span&gt;="Portrait"&lt;span style="color:#ff0000"&gt;
    mc&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;Ignorable&lt;/span&gt;="d"&lt;span style="color:#ff0000"&gt; d&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;DesignHeight&lt;/span&gt;="800"&lt;span style="color:#ff0000"&gt; d&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;DesignWidth&lt;/span&gt;="480"&amp;gt;

    &amp;lt;&lt;span style="color:#a31515"&gt;Grid&lt;/span&gt;&amp;gt;
        &amp;lt;&lt;span style="color:#a31515"&gt;Grid.RowDefinitions&lt;/span&gt;&amp;gt;
            &amp;lt;&lt;span style="color:#a31515"&gt;RowDefinition&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Height&lt;/span&gt;="Auto"/&amp;gt;
            &amp;lt;&lt;span style="color:#a31515"&gt;RowDefinition&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Height&lt;/span&gt;="*"/&amp;gt;
        &amp;lt;/&lt;span style="color:#a31515"&gt;Grid.RowDefinitions&lt;/span&gt;&amp;gt;

        &amp;lt;&lt;span style="color:#a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color:#ff0000"&gt;
            Text&lt;/span&gt;="CHOOSE CUSTOM DATE"&lt;span style="color:#ff0000"&gt;
            Margin&lt;/span&gt;="12"&lt;span style="color:#ff0000"&gt;
            FontWeight&lt;/span&gt;="Bold"/&amp;gt;

        &amp;lt;&lt;span style="color:#a31515"&gt;StackPanel&lt;/span&gt;&lt;span style="color:#ff0000"&gt;
            Grid.Row&lt;/span&gt;="1"&lt;span style="color:#ff0000"&gt;
            VerticalAlignment&lt;/span&gt;="Center"&amp;gt;
            &amp;lt;&lt;span style="color:#a31515"&gt;Button&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Content&lt;/span&gt;="Tomorrow"&lt;span style="color:#ff0000"&gt; Click&lt;/span&gt;="TomorrowButtonClick"/&amp;gt;
            &amp;lt;&lt;span style="color:#a31515"&gt;Button&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Content&lt;/span&gt;="Next Week"&lt;span style="color:#ff0000"&gt; Click&lt;/span&gt;="NextWeekButtonClick"/&amp;gt;
            &amp;lt;&lt;span style="color:#a31515"&gt;Button&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Content&lt;/span&gt;="Next Month"&lt;span style="color:#ff0000"&gt; Click&lt;/span&gt;="NextMonthButtonClick"/&amp;gt;
            &amp;lt;&lt;span style="color:#a31515"&gt;Button&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Content&lt;/span&gt;="[Cancel]"&lt;span style="color:#ff0000"&gt; Click&lt;/span&gt;="CancelButtonClick"/&amp;gt;
        &amp;lt;/&lt;span style="color:#a31515"&gt;StackPanel&lt;/span&gt;&amp;gt;
    &amp;lt;/&lt;span style="color:#a31515"&gt;Grid&lt;/span&gt;&amp;gt;

&amp;lt;/&lt;span style="color:#a31515"&gt;phone&lt;/span&gt;:&lt;span style="color:#a31515"&gt;PhoneApplicationPage&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;pre style="color:#000000"&gt;&lt;span style="color:#0000ff"&gt;public partial class&lt;/span&gt;&lt;span style="color:#2b91af"&gt; CustomDatePickerPage&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;PhoneApplicationPage&lt;/span&gt;, &lt;span style="color:#2b91af;background-color:yellow"&gt;IDateTimePickerPage&lt;/span&gt;
{
    &lt;span style="color:#808080"&gt;/// &amp;lt;summary&amp;gt;
    ///&lt;/span&gt;&lt;span style="color:#008000"&gt; Gets or sets the DateTime value for the IDateTimePickerPage interface.&lt;/span&gt;&lt;span style="color:#808080"&gt;
    /// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span style="background-color:yellow"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="color:#2b91af"&gt; DateTime&lt;/span&gt;? Value { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }&lt;/span&gt;

    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; CustomDatePickerPage()
    {
        InitializeComponent();
    }

    &lt;span style="color:#0000ff"&gt;private void&lt;/span&gt; TomorrowButtonClick(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af"&gt;RoutedEventArgs&lt;/span&gt; e)
    {
        ChooseDate(&lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;.Now.AddDays(1));
    }

    &lt;span style="color:#0000ff"&gt;private void&lt;/span&gt; NextWeekButtonClick(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af"&gt;RoutedEventArgs&lt;/span&gt; e)
    {
        ChooseDate(&lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;.Now.AddDays(7));
    }

    &lt;span style="color:#0000ff"&gt;private void&lt;/span&gt; NextMonthButtonClick(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af"&gt;RoutedEventArgs&lt;/span&gt; e)
    {
        ChooseDate(&lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt;.Now.AddMonths(1));
    }

    &lt;span style="color:#0000ff"&gt;private void&lt;/span&gt; ChooseDate(&lt;span style="color:#2b91af"&gt;DateTime&lt;/span&gt; date)
    {
        &lt;span style="color:#008000;background-color:yellow"&gt;// Commit date and close picker&lt;/span&gt;
        Value = date;
        NavigationService.GoBack();
    }

    &lt;span style="color:#0000ff;"&gt;private void&lt;/span&gt; CancelButtonClick(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af"&gt;RoutedEventArgs&lt;/span&gt; e)
    {
        &lt;span style="color:#008000;background-color:yellow"&gt;// Cancel selection and close picker&lt;/span&gt;
        Value = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;
        NavigationService.GoBack();
    }
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As you can see, creating a custom picker page for &lt;code&gt;DatePicker&lt;/code&gt; and &lt;code&gt;TimePicker&lt;/code&gt; is really easy! As long as you play by a few basic rules, you have &lt;strong&gt;complete&lt;/strong&gt; freedom to style the entire picker experience in a self-contained, interactive, designer-friendly way. It's kind of like re-Templating - but easier and more flexible - in a weird kind of way! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/CustomDateTimePickerPage/CustomDateTimePickerPage.zip"&gt;[Click here to download the complete source code for the CustomDateTimePickerPage sample application.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now get to it - I'm looking forward to seeing the kinds of custom picker experiences you all come up with! &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10065769" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone+Toolkit/">Windows Phone Toolkit</category></item><item><title>See how we make the sausage [Episode 5 of the Inside Windows Phone show highlights the Windows Phone Toolkit!]</title><link>http://blogs.msdn.com/b/delay/archive/2010/09/20/see-how-we-make-the-sausage-episode-5-of-the-inside-windows-phone-show-highlights-the-windows-phone-toolkit.aspx</link><pubDate>Mon, 20 Sep 2010 17:21:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10065138</guid><dc:creator>David Anson</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10065138</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2010/09/20/see-how-we-make-the-sausage-episode-5-of-the-inside-windows-phone-show-highlights-the-windows-phone-toolkit.aspx#comments</comments><description>&lt;div class="delay"&gt;
&lt;p&gt;If you happen to have 11 minutes, 2 seconds lying around and don't know what to do with yourself, you might consider watching or listening to episode 5 of the &lt;a href="http://channel9.msdn.com/Shows/Inside+Windows+Phone"&gt;Inside Windows Phone show&lt;/a&gt; on &lt;a href="http://channel9.msdn.com/"&gt;Channel 9&lt;/a&gt;. Of course, I'm a &lt;strong&gt;bit&lt;/strong&gt; biased - this episode features &lt;a href="http://blogs.msdn.com/b/devdave"&gt;Dave Relyea&lt;/a&gt; and I talking about the new controls in the &lt;a href="http://silverlight.codeplex.com/releases/view/52297"&gt;Silverlight for Windows Phone Toolkit&lt;/a&gt; we just released. Dave and I were two of the four people who created the Phone Toolkit (the others being &lt;a href="http://blogs.msdn.com/b/scmorris/"&gt;Scott Morrison&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/wfaught/"&gt;Will Faught&lt;/a&gt;) and were fortunate to be invited by &lt;a href="http://blogs.msdn.com/b/jaimer/"&gt;Jaime Rodriguez&lt;/a&gt; to talk about it on Channel 9. (If you've never seen a Channel 9 video, it's informal and off-the-cuff. No script and no re-takes - at least for us!) &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Without further ado, here's &lt;a href="http://channel9.msdn.com/Shows/Inside+Windows+Phone/Inside-Windows-Phone-05Windows-Phone-Silverlight-Toolkit"&gt;Inside Windows Phone #05:Windows Phone Silverlight Toolkit&lt;/a&gt;: &lt;/p&gt;
&lt;p&gt;&lt;a href="http://channel9.msdn.com/Shows/Inside+Windows+Phone/Inside-Windows-Phone-05Windows-Phone-Silverlight-Toolkit"&gt;&lt;img height="231" width="391" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/8666.InsideWindowsPhone.jpg" alt="Dave, David, and Jaime" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you enjoyed &lt;strong&gt;that&lt;/strong&gt;, you might also enjoy &lt;a href="http://channel9.msdn.com/Shows/Inside+Windows+Phone/Inside-Windows-Phone-06-Panorama-and-Pivot-are-in-the-house-Woohoo"&gt;Inside Windows Phone #06: Panorama and Pivot are in the house! Woohoo!!&lt;/a&gt; which covers the new Windows Phone &lt;a href="http://msdn.microsoft.com/en-us/library/ff941104(v=VS.92).aspx"&gt;Panorama&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/ff941098(v=VS.92).aspx"&gt;Pivot&lt;/a&gt; controls. This was another project Dave Relyea, Scott Morrison, and I were involved in - along with &lt;a href="http://www.jeff.wilcox.name/blog/"&gt;Jeff Wilcox&lt;/a&gt; (who's featured in the video). &lt;/p&gt;
&lt;p&gt;Thanks a lot to Jaime and the Channel 9 folks for creating these videos. I hope you find them useful - or at least entertaining! &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10065138" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone+Toolkit/">Windows Phone Toolkit</category></item><item><title>Pining for Windows Phone 7 controls? We got ya covered! [Announcing the first release of the Silverlight for Windows Phone Toolkit!]</title><link>http://blogs.msdn.com/b/delay/archive/2010/09/16/pining-for-windows-phone-7-controls-we-got-ya-covered-announcing-the-first-release-of-the-silverlight-for-windows-phone-toolkit.aspx</link><pubDate>Thu, 16 Sep 2010 16:54:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10063348</guid><dc:creator>David Anson</dc:creator><slash:comments>31</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/delay/rsscomments.aspx?WeblogPostID=10063348</wfw:commentRss><comments>http://blogs.msdn.com/b/delay/archive/2010/09/16/pining-for-windows-phone-7-controls-we-got-ya-covered-announcing-the-first-release-of-the-silverlight-for-windows-phone-toolkit.aspx#comments</comments><description>&lt;div class="delay"&gt;&lt;img height="554" width="305" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/0753.WpTkSep10_2D00_Sample.png" alt="Phone Toolkit Sample Application" style="float:right;margin-left:10px" /&gt;
&lt;p&gt;Today marks the official release of the &lt;a href="http://developer.windowsphone.com/windows-phone-7/"&gt;Windows Phone Developer Tools&lt;/a&gt;. This free download enables anyone to create .NET applications for the &lt;strong&gt;Windows Phone 7&lt;/strong&gt; platform using the Silverlight framework (for traditional applications) or the XNA framework (for games). The Windows Phone 7 application development experience is fully integrated with Visual Studio 2010 and Blend 4 and also includes an emulator for running and testing applications without having a phone. It's really cool stuff, and I encourage everyone to &lt;a href="http://developer.windowsphone.com/windows-phone-7/"&gt;learn more about Windows Phone 7 development&lt;/a&gt;! &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Congratulations to the Windows Phone 7 team on their accomplishment! &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To celebrate, there's a &lt;strong&gt;new&lt;/strong&gt; download for the &lt;a href="http://silverlight.codeplex.com/"&gt;Silverlight Toolkit CodePlex project&lt;/a&gt;: the &lt;a href="http://silverlight.codeplex.com/releases/view/52297"&gt;Silverlight for Windows Phone Toolkit September 2010 release&lt;/a&gt;! Yes, that's right - in addition to providing controls for Silverlight developers targeting the desktop, we're &lt;strong&gt;also&lt;/strong&gt; providing controls for Silverlight developers targeting Windows Phone 7! As you might guess, the Windows Phone Toolkit is a &lt;strong&gt;lot&lt;/strong&gt; like the Silverlight Toolkit: the goal is still to provide a set of controls that complement the platform's core offering and help developers/designers create more compelling, more platform-consistent user experiences simply and easily. Because &lt;strong&gt;we&lt;/strong&gt; focus on writing solid, reusable controls that address common scenarios, &lt;strong&gt;you&lt;/strong&gt; are free to focus on delivering an engaging, compelling application to your customers! &lt;/p&gt;
&lt;p&gt;As with the Silverlight Toolkit, the Windows Phone Toolkit comes with full source code (under &lt;a href="http://opensource.org/licenses/ms-pl.html"&gt;the permissive OSI-approved Ms-PL license&lt;/a&gt;) to help people learn the techniques behind developing rich, platform-consistent controls, to see how we solved a particular problem, or to make tweaks and improvements to the controls themselves! The idea is to publish the Windows Phone Toolkit every few months or so; each release will include new controls, improvements to existing controls, and fixes for any bugs people run into. If you have a suggestion for something we should add or change, please search for that issue in the &lt;a href="http://silverlight.codeplex.com/workitem/list/basic"&gt;CodePlex issue tracker&lt;/a&gt; and vote for it (or create a &lt;strong&gt;new&lt;/strong&gt; issue if your idea is unique). We pay attention to the number of votes an issue has when prioritizing our efforts - it helps ensure we're delivering what the &lt;strong&gt;community&lt;/strong&gt; wants! &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Okay, after all that intro and background, you're probably wondering what's actually &lt;strong&gt;in&lt;/strong&gt; the Phone Toolkit... &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="font-size:12pt"&gt;&lt;strong&gt;What's in the Phone Toolkit?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ContextMenu and ContextMenuService&lt;/strong&gt;&lt;/p&gt;
&lt;img height="133" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/0257.WpTkSep10_2D00_ContextMenu.png" alt="ContextMenu sample" /&gt;
&lt;p&gt;In desktop applications, &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contextmenu.aspx"&gt;ContextMenu&lt;/a&gt; is handy because it lets the second mouse button perform additional, contextually-relevant tasks; but on the &lt;strong&gt;phone&lt;/strong&gt;, it's practically a &lt;strong&gt;requirement&lt;/strong&gt;! Phone-sized UIs need to use every pixel to its fullest advantage, so being able to hide secondary commands behind a tap+hold gesture is a great way to keep the interface clean and easy to read. &lt;/p&gt;
&lt;p&gt;The Windows Phone Toolkit's &lt;code&gt;ContextMenu&lt;/code&gt; control is a direct port of the Silverlight 4 Toolkit's &lt;code&gt;ContextMenu&lt;/code&gt; (&lt;a href="http://blogs.msdn.com/b/delay/archive/2010/04/15/alive-and-kickin-new-silverlight-4-toolkit-released-with-today-s-silverlight-4-rtw.aspx"&gt;read more about what it does and how it works here&lt;/a&gt;) with additional Windows Phone-specific functionality added on top. So the Phone &lt;code&gt;ContextMenu&lt;/code&gt; uses the same, great 100% Silverlight- and WPF-compatible &lt;a href="http://msdn.microsoft.com/en-us/library/bb613556.aspx"&gt;ItemsControl&lt;/a&gt;-based API you know and love - plus it looks good on the phone and behaves just like the system's &lt;code&gt;ContextMenu&lt;/code&gt; does! Which means &lt;code&gt;ContextMenu&lt;/code&gt; (along with its helper &lt;code&gt;ContextMenuService&lt;/code&gt;) is simple to use and makes it &lt;strong&gt;easy&lt;/strong&gt; for Windows Phone applications to maintain platform-consistent appearance and behavior. (And for advanced scenarios, &lt;code&gt;ContextMenu&lt;/code&gt; supports the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.input.icommand.aspx"&gt;ICommand&lt;/a&gt; interface, data-binding (of and to) items, &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.separator.aspx"&gt;Separator&lt;/a&gt;, and more!) &lt;/p&gt;
&lt;p&gt;Here's the XAML for the example above: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;Border
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;    Background&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; PhoneChromeBrush&lt;/span&gt;}"
&lt;span style="color:#ff0000"&gt;    Padding&lt;/span&gt;="20"&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;ContextMenuService.ContextMenu&lt;/span&gt;&amp;gt;
        &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;ContextMenu&lt;/span&gt;&amp;gt;
            &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;MenuItem
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;                Header&lt;/span&gt;="gray text"
&lt;span style="color:#ff0000"&gt;                Click&lt;/span&gt;="MenuGrayTextClick"/&amp;gt;
            &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;MenuItem
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;                Header&lt;/span&gt;="normal text"
&lt;span style="color:#ff0000"&gt;                Click&lt;/span&gt;="MenuNormalTextClick"/&amp;gt;
        &amp;lt;/&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;ContextMenu&lt;/span&gt;&amp;gt;
    &amp;lt;/&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;ContextMenuService.ContextMenu&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;TextBlock
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;        x&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;Name&lt;/span&gt;="MenuTextBlock"
&lt;span style="color:#ff0000"&gt;        Text&lt;/span&gt;="Tap and hold for ContextMenu"
&lt;span style="color:#ff0000"&gt;        HorizontalAlignment&lt;/span&gt;="Center"/&amp;gt;
&amp;lt;/&lt;span style="color:#a31515"&gt;Border&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;DatePicker and TimePicker&lt;/strong&gt;&lt;/p&gt;
&lt;img height="96" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/8686.WpTkSep10_2D00_DateTimePickerButtons.png" alt="DatePicker and TimePicker sample buttons" /&gt; &lt;img height="400" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/8508.WpTkSep10_2D00_DatePickerPage.png" alt="DatePicker and TimePicker sample picker" style="float:right;margin-left:10px" /&gt;
&lt;p&gt;Windows Phone 7 includes a cool, distinctive UI for choosing dates and times: three vertical spinners create a fun "endless looping" experience that people really enjoy using. The Phone Toolkit's &lt;code&gt;DatePicker&lt;/code&gt; and &lt;code&gt;TimePicker&lt;/code&gt; controls implement the &lt;strong&gt;exact&lt;/strong&gt; same experience as the core controls, so it's easy to add date and time selection to your own application! &lt;/p&gt;
&lt;p&gt;What's more, these controls are both culture-aware and automatically configure themselves according to the settings on the user's phone (ex: &lt;code&gt;d/m/y&lt;/code&gt; vs. &lt;code&gt;m/d/y&lt;/code&gt; date formats and 12- vs. 24-hour time format). The API for &lt;code&gt;DatePicker&lt;/code&gt; and &lt;code&gt;TimePicker&lt;/code&gt; will be familiar to anyone who's used similar "picker" controls in the past. The &lt;code&gt;Header&lt;/code&gt; convenience property simplifies the task of labeling either control - in a platform-consistent font and style! &lt;/p&gt;
&lt;p&gt;Here's the XAML for the example above and to the right: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;DatePicker
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;    Header&lt;/span&gt;="Date"
&lt;span style="color:#ff0000"&gt;    Value&lt;/span&gt;="9/16/2010"
&lt;span style="color:#ff0000"&gt;    ValueChanged&lt;/span&gt;="DatePickerValueChanged"/&amp;gt;
&amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;TimePicker
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;    Header&lt;/span&gt;="Time"
&lt;span style="color:#ff0000"&gt;    Value&lt;/span&gt;="12:34 pm"
&lt;span style="color:#ff0000"&gt;    ValueChanged&lt;/span&gt;="TimePickerValueChanged"/&amp;gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ToggleSwitch&lt;/strong&gt;&lt;/p&gt;
&lt;img height="79" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/3312.WpTkSep10_2D00_ToggleSwitch.png" alt="ToggleSwitch sample" /&gt;
&lt;p&gt;The Windows Phone UI for toggling settings on and off will be immediately familiar to anyone who's used a light switch (or an &lt;em&gt;iDevice&lt;/em&gt;). Because there are subtleties to the core controls that are tricky to get right, the Toolkit includes the &lt;code&gt;ToggleSwitch&lt;/code&gt; control! Continuing the theme of "make it easy to match the core behavior", &lt;code&gt;ToggleSwitch&lt;/code&gt; looks, feels, and acts &lt;strong&gt;just&lt;/strong&gt; like Windows Phone users will expect - including supporting flicks and swipes. In addition to subclassing &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.togglebutton(VS.95).aspx"&gt;ToggleButton&lt;/a&gt; for consistency and usability, &lt;code&gt;ToggleSwitch&lt;/code&gt; supports the &lt;code&gt;Header&lt;/code&gt; convenience property to make it easy to create properly-spaced settings pages. And if the need arises, you can also provide custom &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.content(v=VS.95).aspx"&gt;Content&lt;/a&gt; or pull the &lt;code&gt;ToggleSwitchButton&lt;/code&gt; primitive control out and use it directly! &lt;/p&gt;
&lt;p&gt;Here's the XAML for the example above: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;ToggleSwitch
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;    Header&lt;/span&gt;="Some feature"
&lt;span style="color:#ff0000"&gt;    IsChecked&lt;/span&gt;="true"
&lt;span style="color:#ff0000"&gt;    Checked&lt;/span&gt;="ToggleSwitchChanged"
&lt;span style="color:#ff0000"&gt;    Unchecked&lt;/span&gt;="ToggleSwitchChanged"/&amp;gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;GestureListener and GestureService&lt;/strong&gt;&lt;/p&gt;
&lt;img height="65" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/5047.WpTkSep10_2D00_GestureListener.png" alt="GestureService and GestureListener sample" /&gt;
&lt;p&gt;Touch interfaces are a lot more interactive and engaging than the conventional mouse+keyboard UI most people are used to. One of the neatest things about touch UIs are their ability to translate natural human gestures into meaningful commands. Taking good advantage of touch and gestures can &lt;strong&gt;significantly&lt;/strong&gt; improve the user experience and really help an application stand out from the crowd. &lt;/p&gt;
&lt;p&gt;To make gestures easy to work with, the Phone Toolkit includes the &lt;code&gt;GestureService&lt;/code&gt; and &lt;code&gt;GestureListener&lt;/code&gt; classes which provide events for the following gestures: tap, double-tap, hold, flick, drag (started/delta/completed), and pinch (started/delta/completed). All these gestures respect the relevant system parameters (ex: movement threshold, input timing, etc.), so applications that use &lt;code&gt;GestureListener&lt;/code&gt; feel familiar and natural. All the developer needs to do is associate a &lt;code&gt;GestureListener&lt;/code&gt; with the element(s) of interest and handle the corresponding gesture event(s) as they show up! &lt;/p&gt;
&lt;p&gt;For more background on gestures, &lt;a href="http://msdn.microsoft.com/en-us/library/dd940543.aspx"&gt;here's a nice, easy to visualize overview for Windows 7&lt;/a&gt; (not identical, but close) and &lt;a href="http://creators.xna.com/en-US/article/gestures"&gt;here's a detailed document specific to windows Phone 7&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;Here's the XAML for the example above (note that typical applications will only hook up to the event(s) they care about): &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;Border
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;    Background&lt;/span&gt;="{&lt;span style="color:#a31515"&gt;StaticResource&lt;/span&gt;&lt;span style="color:#ff0000"&gt; PhoneChromeBrush&lt;/span&gt;}"
&lt;span style="color:#ff0000"&gt;    Padding&lt;/span&gt;="40"&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;GestureService.GestureListener&lt;/span&gt;&amp;gt;
        &amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;GestureListener
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;            Tap&lt;/span&gt;="GestureListenerTap"
&lt;span style="color:#ff0000"&gt;            DoubleTap&lt;/span&gt;="GestureListenerDoubleTap"
&lt;span style="color:#ff0000"&gt;            Hold&lt;/span&gt;="GestureListenerHold"
&lt;span style="color:#ff0000"&gt;            Flick&lt;/span&gt;="GestureListenerFlick"
&lt;span style="color:#ff0000"&gt;            DragStarted&lt;/span&gt;="GestureListenerDragStarted"
&lt;span style="color:#ff0000"&gt;            DragDelta&lt;/span&gt;="GestureListenerDragDelta"
&lt;span style="color:#ff0000"&gt;            DragCompleted&lt;/span&gt;="GestureListenerDragCompleted"
&lt;span style="color:#ff0000"&gt;            PinchStarted&lt;/span&gt;="GestureListenerPinchStarted"
&lt;span style="color:#ff0000"&gt;            PinchDelta&lt;/span&gt;="GestureListenerPinchDelta"
&lt;span style="color:#ff0000"&gt;            PinchCompleted&lt;/span&gt;="GestureListenerPinchCompleted"/&amp;gt;
    &amp;lt;/&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;GestureService.GestureListener&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;TextBlock
&lt;/span&gt;&lt;span style="color:#ff0000"&gt;        x&lt;/span&gt;:&lt;span style="color:#ff0000"&gt;Name&lt;/span&gt;="GestureTextBlock"
&lt;span style="color:#ff0000"&gt;        Text&lt;/span&gt;="Perform any gesture here"
&lt;span style="color:#ff0000"&gt;        HorizontalAlignment&lt;/span&gt;="Center"/&amp;gt;
&amp;lt;/&lt;span style="color:#a31515"&gt;Border&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;WrapPanel&lt;/strong&gt;&lt;/p&gt;
&lt;img height="109" width="240" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/8508.WpTkSep10_2D00_WrapPanel.png" alt="WrapPanel sample" /&gt;
&lt;p&gt;It may not be the sexiest of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.panel(VS.95).aspx"&gt;Panel&lt;/a&gt; classes, but &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.wrappanel.aspx"&gt;WrapPanel&lt;/a&gt; is a tremendously useful layout container! Lots of Windows Phone developers have been using this control from the &lt;a href="http://silverlight.codeplex.com/releases/view/36060"&gt;Silverlight 3 Toolkit&lt;/a&gt; (either by referencing that assembly or by copying the code into their projects), but that can be a little tricky - so we thought we'd make it super easy by including &lt;code&gt;WrapPanel&lt;/code&gt; in the Phone Toolkit! &lt;code&gt;WrapPanel&lt;/code&gt;'s "put as much stuff on a line as fits, then wrap to the next line" approach works &lt;strong&gt;particularly&lt;/strong&gt; well on the phone - especially for scenarios where the sizes of things can vary (ex: during the transition from portrait orientation to landscape). &lt;/p&gt;
&lt;p&gt;Here's the XAML for the example above: &lt;/p&gt;
&lt;pre style="color:#0000ff"&gt;&amp;lt;&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;WrapPanel&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;Button&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Content&lt;/span&gt;="Here"/&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;Button&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Content&lt;/span&gt;="is"/&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;Button&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Content&lt;/span&gt;="some"/&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;Button&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Content&lt;/span&gt;="simple"/&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;Button&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Content&lt;/span&gt;="content"/&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;Button&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Content&lt;/span&gt;="that"/&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;Button&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Content&lt;/span&gt;="wraps"/&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;Button&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Content&lt;/span&gt;="to"/&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;Button&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Content&lt;/span&gt;="fit"/&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;Button&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Content&lt;/span&gt;="the"/&amp;gt;
    &amp;lt;&lt;span style="color:#a31515"&gt;Button&lt;/span&gt;&lt;span style="color:#ff0000"&gt; Content&lt;/span&gt;="screen"/&amp;gt;
&amp;lt;/&lt;span style="color:#a31515"&gt;toolkit&lt;/span&gt;:&lt;span style="color:#a31515"&gt;WrapPanel&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="font-size:12pt"&gt;&lt;strong&gt;&lt;a href="http://cesso.org/Samples/PhoneToolkitSamplesSeptember10/PhoneToolkitSamplesSeptember10.zip"&gt;[Click here to download the sample application used to create all the examples shown here.]&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="font-size:12pt"&gt;&lt;strong&gt;Helpful Hints for Hopeful Heroes&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Here are a few tips and tidbits to help fledgling Windows Phone 7 developers make the most of the Phone Toolkit: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The examples I show here are from my own (deliberately simple) sample application, but there's also a more comprehensive sample application that shows off more sophisticated scenarios. The complete source code for the &lt;strong&gt;entire&lt;/strong&gt; Phone Toolkit (&lt;strong&gt;including&lt;/strong&gt; the sample application) can be downloaded from the &lt;a href="http://silverlight.codeplex.com/releases/view/52297"&gt;CodePlex release page&lt;/a&gt; or the &lt;a href="http://silverlight.codeplex.com/SourceControl/list/changesets"&gt;CodePlex source code page&lt;/a&gt; or by using any of the supported version control system clients (ex: TFS, SVN, etc.). &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Some (but not all) of the &lt;code&gt;ContextMenu&lt;/code&gt;s used by the core phone applications get a little fancy when they show the menu: they shrink the UI of the rest of the application in the background. Because we strive to help developers create consistent applications, the Toolkit's &lt;code&gt;ContextMenu&lt;/code&gt; does this by default as well. &lt;/p&gt;
&lt;p&gt;But because it's not part of the application itself, our &lt;code&gt;ContextMenu&lt;/code&gt;'s behavior needs to be as self-contained as possible - which means it can &lt;strong&gt;not&lt;/strong&gt; modify the existing visuals in order to create this effect. (Otherwise it might make an unexpected change that crashes the developer's application!) Therefore, the "shrink" effect is implemented by capturing a "background" screen shot of the entire application, layering it over an opaque &lt;code&gt;PhoneBackgroundBrush&lt;/code&gt; layer to avoid transparent areas leaking through, creating a "active element" screen shot capture of just the element that was tap+held, layering this over a correspondingly-sized opaque &lt;code&gt;PhoneBackgroundBrush&lt;/code&gt; layer (to avoid transparency issues again), creating a "menu" layer for the actual menu items, layering &lt;strong&gt;everything&lt;/strong&gt; over the running application by putting it in a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.popup(VS.95).aspx"&gt;Popup&lt;/a&gt;, and finally animating the scale of the "background" layers. Whew - if that sounds like a lot of effort, it &lt;strong&gt;is&lt;/strong&gt;... &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;p&gt;The good news is this works pretty well in practice and duplicates the core effect fairly authentically - the less good news is that certain page designs poke little holes in the sleight-of-hand &lt;code&gt;ContextMenu&lt;/code&gt; is doing. In many cases, such issues can be resolved by modifying the target element (the one to which the &lt;code&gt;ContextMenu&lt;/code&gt; is attached) to have a non-transparent background. (&lt;code&gt;ContextMenu&lt;/code&gt;'s &lt;code&gt;PhoneBackgroundBrush&lt;/code&gt; guess is the best it can do, but the application developer can sometimes do &lt;strong&gt;better&lt;/strong&gt;.) &lt;/p&gt;
&lt;p&gt;But if you still can't get the effect you're looking for - or if you just don't like the default "shrink and grow" behavior (the core applications don't use it everywhere, either!) - then you can set the (Phone-specific) &lt;code&gt;ContextMenu.IsZoomEnabled&lt;/code&gt; property to &lt;code&gt;false&lt;/code&gt; in order to disable the custom animation and get rid of &lt;strong&gt;all&lt;/strong&gt; this goofy complexity. In every case I know of so far, developers who resorted to &lt;code&gt;IsZoomEnabled&lt;/code&gt; were quite happy with the results! &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;img height="455" width="284" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-60-92-metablogapi/3301.WpTkSep10_2D00_IconConfiguration.png" alt="Icon configuration" style="float:right;margin-left:10px" /&gt; When you first add &lt;code&gt;DatePicker&lt;/code&gt; or &lt;code&gt;TimePicker&lt;/code&gt; to your application, you'll find that the "done" and "cancel" &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.applicationbar(VS.92).aspx"&gt;ApplicationBar&lt;/a&gt; icons shown when the pickers are opened are wrong. That's because the icons aren't actually being loaded - and &lt;strong&gt;that's&lt;/strong&gt; because of a platform restriction. Specifically, the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.applicationbariconbutton.iconuri(v=VS.92).aspx"&gt;ApplicationBarButton.IconUri&lt;/a&gt; property will &lt;strong&gt;only&lt;/strong&gt; load images that are part of the project and marked with &lt;code&gt;Build Action=Content&lt;/code&gt; in the property editor. This means there's no &lt;strong&gt;good&lt;/strong&gt; way for an assembly like the Phone Toolkit assembly to bundle such icons within itself (like there would be if the &lt;code&gt;IconUri&lt;/code&gt; property supported the &lt;a href="http://msdn.microsoft.com/library/cc296240(VS.95).aspx"&gt;assembly-relative syntax "/assemblyShortName;component/resourceLocation"&lt;/a&gt;). &lt;/p&gt;
&lt;p&gt;As a result, it's necessary for application developers to add these two icons to a well-known path in their project where &lt;code&gt;DatePicker&lt;/code&gt; and &lt;code&gt;TimePicker&lt;/code&gt; will automatically use them. For your convenience, we've bundled these two icons along with the Toolkit installer and they're &lt;strong&gt;already&lt;/strong&gt; on your machine! &lt;nobr&gt;:)&lt;/nobr&gt; To find them, open the Start Menu, expand the "Microsoft Silverlight for Windows Phone Toolkit" folder, and click on the "Binaries" item. This will open a Windows Explorer view of the install location of the Phone Toolkit (something like &lt;code&gt;C:\Program Files\Microsoft SDKs\Windows Phone\v7.0\Toolkit\Sep10\Bin&lt;/code&gt;). The icons can be found in the "Icons" sub-folder within. &lt;/p&gt;
&lt;p&gt;To use these two icons in an application, right click the application's project node in the Visual Studio Solution Explorer, choose "Add", choose "New Folder", and rename it "Toolkit.Content". Then right-click on the new folder, choose "Add", choose "Existing Item...", navigate to the Phone Toolkit's install directory, select both icons, and hit "OK". Right-click each icon and change its "Build Action" to "Content"; re-run the application, and they'll show up just like you expect! (And if any of that seemed confusing, just look at how the sample application is configured - match that and you'll be fine.) &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you already know Windows Phone 7 supports different themes ("Light" and "Dark", AKA "white background" and "black background"), you might wonder why it's not necessary to provide "Light" &lt;strong&gt;and&lt;/strong&gt; "Dark" versions of each icon... Well, the platform's a little clever here - it will &lt;strong&gt;automatically&lt;/strong&gt; "Light"-ify "Dark" icons when the "Light" theme is active. Therefore, all we need to do is provide is "Dark" versions of the icons - the system converts them for us! &lt;/p&gt;
&lt;blockquote&gt;&lt;strong&gt;Note&lt;/strong&gt;: The reverse is &lt;strong&gt;not&lt;/strong&gt; true; "Light" icons will not be "Dark"-ified for you. (So it seems like maybe the &lt;a href="http://en.wikipedia.org/wiki/Dark_side_(Star_Wars)"&gt;"Dark" side&lt;/a&gt; is more powerful?) &lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We've already discussed the reasons why it's good for controls to use the &lt;code&gt;Popup&lt;/code&gt; control (because it keeps things isolated from the rest of the application), so &lt;code&gt;DatePicker&lt;/code&gt; and &lt;code&gt;TimePicker&lt;/code&gt; obviously use &lt;code&gt;Popup&lt;/code&gt; too, right? &lt;strong&gt;Wrong!&lt;/strong&gt; &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;p&gt;To be fair, &lt;code&gt;DatePicker&lt;/code&gt; and &lt;code&gt;TimePicker&lt;/code&gt; originally used a &lt;code&gt;Popup&lt;/code&gt; for &lt;strong&gt;exactly&lt;/strong&gt; those reasons. And life was good. Except when you tried to scroll the time/date spinners in the picker view... It worked okay, but the frame-rate was pretty low - almost as if the animations weren't happening on the composition (render) thread like they were supposed to... And, indeed, they &lt;strong&gt;weren't&lt;/strong&gt;! It turns out the phone platform doesn't apply hardware acceleration to content in a &lt;code&gt;Popup&lt;/code&gt;. &lt;nobr&gt;:(&lt;/nobr&gt; &lt;/p&gt;
&lt;p&gt;Enough people were unhappy with the performance that &lt;code&gt;DatePicker&lt;/code&gt; and &lt;code&gt;TimePicker&lt;/code&gt; were modified to use a &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.phoneapplicationpage(VS.92).aspx"&gt;PhoneApplicationPage&lt;/a&gt;-based model instead. What this means is that instead of opening a &lt;code&gt;Popup&lt;/code&gt; to hold the picker's spinner UI, these controls instead call &lt;a href="http://msdn.microsoft.com/en-us/library/ms591053(v=VS.92).aspx"&gt;NavigationService.Navigate("...")&lt;/a&gt; and point it to a &lt;code&gt;Page&lt;/code&gt; subclass that's hosted in the &lt;strong&gt;same&lt;/strong&gt; control assembly. The platform doesn't care where it loads pages from, so it happily navigates to the new &lt;code&gt;Page&lt;/code&gt;, which then loads the spinners, which benefit from hardware acceleration, and therefore scroll smoothly! &lt;/p&gt;
&lt;p&gt;If this sounds like a wonderful solution, that's because it is - &lt;strong&gt;mostly&lt;/strong&gt;. The big drawback to the &lt;code&gt;Page&lt;/code&gt;-based approach is that it subtly &lt;strong&gt;breaks&lt;/strong&gt; one of the guidelines of control development we discussed above: don't make changes that affect the application. In this case, if the application is already listening to the &lt;a href="http://msdn.microsoft.com/en-us/library/ms615507(v=VS.92).aspx"&gt;NavigationService&lt;/a&gt;'s &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.navigation.navigationservice.navigating(v=VS.92).aspx"&gt;Navigating&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.navigation.navigationservice.navigated(v=VS.92).aspx"&gt;Navigated&lt;/a&gt; events, then it will also see the "hidden" navigations that &lt;code&gt;DatePicker&lt;/code&gt; and &lt;code&gt;TimePicker&lt;/code&gt; are performing. &lt;/p&gt;
&lt;p&gt;Whether this is a problem or not depends on what the application is doing and how it's doing it. The good news is that most applications don't track navigations and won't need to worry about this at all; for applications that &lt;strong&gt;do&lt;/strong&gt; track navigations, the good news is that this scenario is easy to detect. Specifically, if the object exposed by &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.navigation.navigationeventargs.content.aspx"&gt;NavigationEventArgs.Content&lt;/a&gt; during a navigation implements &lt;code&gt;IDateTimePickerPage&lt;/code&gt;, then the current navigation is part of &lt;code&gt;DatePicker&lt;/code&gt; or &lt;code&gt;TimePicker&lt;/code&gt;'s behavior and should be &lt;strong&gt;ignored&lt;/strong&gt; by the application. Applications that follow that simple guideline &lt;strong&gt;should&lt;/strong&gt; be safe; applications that ignore it and play tricks like cancelling &lt;code&gt;DatePicker&lt;/code&gt; and &lt;code&gt;TimePicker&lt;/code&gt; navigations will most likely &lt;strong&gt;break&lt;/strong&gt; stuff. &lt;nobr&gt;:(&lt;/nobr&gt; &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now that I've thoroughly scared everyone away from ever using &lt;code&gt;Page&lt;/code&gt;-based navigations, let me back-pedal a bit and say that there are some cool things you can do with them! In particular, &lt;code&gt;DatePicker&lt;/code&gt; and &lt;code&gt;TimePicker&lt;/code&gt; allow you to customize their destination &lt;code&gt;Page&lt;/code&gt; which lets you completely change the picker experience for both of them. But I've already gone on long enough here; that'll be the topic of a &lt;strong&gt;subsequent&lt;/strong&gt; blog post... &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We've had a lot of fun building the Silverlight for Windows Phone Toolkit - and we hope &lt;strong&gt;you&lt;/strong&gt; have a lot of fun using it! Everything in the Phone Toolkit is there because there was &lt;strong&gt;strong&lt;/strong&gt; customer demand. The Silverlight Toolkit team has heard you loud and clear, and we're doing our best to make your Windows Phone 7 development experience as pleasant and productive as possible! &lt;/p&gt;
&lt;p&gt;Okay, enough chatter for now - go download the developer tools and get busy building great applications! &lt;nobr&gt;:)&lt;/nobr&gt; &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10063348" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Silverlight+Toolkit/">Silverlight Toolkit</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone/">Windows Phone</category><category domain="http://blogs.msdn.com/b/delay/archive/tags/Windows+Phone+Toolkit/">Windows Phone Toolkit</category></item></channel></rss>
