<?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>stephanc's blog</title><link>http://blogs.msdn.com/b/stephanc/</link><description>Mumbling about stuff...</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>Windows Phone 7 Pivot Control sample</title><link>http://blogs.msdn.com/b/stephanc/archive/2010/05/09/windows-phone-7-pivot-control-sample.aspx</link><pubDate>Sun, 09 May 2010 18:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10009909</guid><dc:creator>Stephane Crozatier</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/stephanc/rsscomments.aspx?WeblogPostID=10009909</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/stephanc/commentapi.aspx?WeblogPostID=10009909</wfw:comment><comments>http://blogs.msdn.com/b/stephanc/archive/2010/05/09/windows-phone-7-pivot-control-sample.aspx#comments</comments><description>&lt;P&gt;Today i am releasing the first preview of the &lt;A href="http://phone.codeplex.com/" mce_href="http://phone.codeplex.com/"&gt;Pivot Control for Windows Phone 7&lt;/A&gt;. &lt;BR&gt;Like the &lt;EM&gt;&lt;A href="http://blogs.msdn.com/stephanc/archive/2010/04/04/windows-phone-7-panorama-control-sample.aspx" mce_href="http://blogs.msdn.com/stephanc/archive/2010/04/04/windows-phone-7-panorama-control-sample.aspx"&gt;Panorama Control&lt;/A&gt;&lt;/EM&gt;, this is intended to be a sample code you can re-use in your own Windows Phone app, or as a learning experience for Silverlight (that’s my case).&lt;/P&gt;
&lt;P&gt;So, what is a Pivot control ?&lt;/P&gt;
&lt;P&gt;I guess you’re all familiar with the &lt;A href="http://msdn.microsoft.com/en-us/library/bb760550.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb760550.aspx"&gt;Tab Control&lt;/A&gt; concept. If not, here’s a quote from the MSDN documentation of the Win32 Tab Control:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;“A tab control is analogous to the dividers in a notebook or the labels in a file cabinet. By using a tab control, an application can define multiple pages for the same area of a window or dialog box. Each page consists of a certain type of information or a group of controls that the application displays when the user selects the corresponding tab.”&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well, a Pivot Control is very similar to that, except for navigation. There are two ways to navigate from one page to another : you can either click the page’s &lt;EM&gt;Header&lt;/EM&gt;, or simply flick through the pages.&lt;/P&gt;
&lt;P&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: block; FLOAT: none; MARGIN-LEFT: auto; BORDER-TOP: 0px; MARGIN-RIGHT: auto; BORDER-RIGHT: 0px" title=pivot-ctrl border=0 alt=pivot-ctrl src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PivotControlsample_1043F/pivot-ctrl_3.png" width=629 height=480 mce_src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PivotControlsample_1043F/pivot-ctrl_thumb.png"&gt; &lt;/P&gt;
&lt;H3&gt;The control&lt;/H3&gt;
&lt;P&gt;The &lt;EM&gt;PivotControl&lt;/EM&gt; was built using the exact same paradigm as the &lt;EM&gt;PanoramaControl&lt;/EM&gt;. It derives from the &lt;EM&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol(VS.95).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol(VS.95).aspx"&gt;ItemsControl&lt;/A&gt;&lt;/EM&gt; class, provides it’s own UI and navigation system. You can assign it a &lt;EM&gt;Title&lt;/EM&gt;, although this is completely optional if each page also specifies a &lt;EM&gt;Title&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;Each section of the control is called the &lt;EM&gt;PivotItem&lt;/EM&gt;. The &lt;EM&gt;PivotItem&lt;/EM&gt; has a &lt;EM&gt;Header&lt;/EM&gt; and a &lt;EM&gt;Title&lt;/EM&gt;. When a &lt;EM&gt;PivotItem&lt;/EM&gt; is selected, its &lt;EM&gt;Title&lt;/EM&gt; will replace the main control’s Title (on the top) and also animate the &lt;EM&gt;Headers&lt;/EM&gt; list. The selected &lt;EM&gt;PivotItem&lt;/EM&gt;’s &lt;EM&gt;Header&lt;/EM&gt; will then move to the left of the screen, and it’s template will change to highlight the selected &lt;EM&gt;PivotItem&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: block; FLOAT: none; MARGIN-LEFT: auto; BORDER-TOP: 0px; MARGIN-RIGHT: auto; BORDER-RIGHT: 0px" title=pivot-ctrl-layout border=0 alt=pivot-ctrl-layout src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PivotControlsample_1043F/pivot-ctrl-layout_3.png" width=627 height=480 mce_src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PivotControlsample_1043F/pivot-ctrl-layout_thumb.png"&gt; &lt;/P&gt;
&lt;H3&gt;Using the control&lt;/H3&gt;
&lt;P&gt;Each &lt;EM&gt;PivotItem&lt;/EM&gt; has a (implicit) &lt;EM&gt;Content&lt;/EM&gt; property. This is where you integrate your own group of controls.&lt;/P&gt;
&lt;P&gt;Just like the PanoramaControl, the design-time experience here is far from perfect. You’ll probably be better off populating the control in XAML directly. &lt;/P&gt;
&lt;P&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: block; FLOAT: none; MARGIN-LEFT: auto; BORDER-TOP: 0px; MARGIN-RIGHT: auto; BORDER-RIGHT: 0px" title=pivot-ctrl-xaml border=0 alt=pivot-ctrl-xaml src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PivotControlsample_1043F/pivot-ctrl-xaml_1.png" width=562 height=484 mce_src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PivotControlsample_1043F/pivot-ctrl-xaml_thumb_2.png"&gt;&lt;/P&gt;
&lt;P&gt;Contrary to the &lt;EM&gt;PanoramaControl&lt;/EM&gt;, i believe that there are many scenarios where the &lt;EM&gt;PivotControl&lt;/EM&gt; will be populated dynamically by code. &lt;BR&gt;This is the case for applications that need to show a variable number of pages that share the same layout (but not only). A good example for this is a Weather forecasting application : you can choose to show forecast data for a variable number of cities, but each page will be built using the same structure.&lt;/P&gt;
&lt;P&gt;The way to achieve this is by creating a empty &lt;EM&gt;PivotControl&lt;/EM&gt; using XAML, and then create and populate the &lt;EM&gt;PivotItems&lt;/EM&gt; by code as shown below.&lt;/P&gt;
&lt;P&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: block; FLOAT: none; MARGIN-LEFT: auto; BORDER-TOP: 0px; MARGIN-RIGHT: auto; BORDER-RIGHT: 0px" title=pivot-ctrl-code border=0 alt=pivot-ctrl-code src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PivotControlsample_1043F/pivot-ctrl-code_3.png" width=404 height=176 mce_src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PivotControlsample_1043F/pivot-ctrl-code_thumb.png"&gt; &lt;/P&gt;
&lt;H3&gt;Navigation&lt;/H3&gt;
&lt;P&gt;As i described above, the &lt;EM&gt;Header&lt;/EM&gt; portion of the &lt;EM&gt;PivotItem&lt;/EM&gt; is sensitive to clicks so one way to navigate from one page to another is to click the &lt;EM&gt;Header&lt;/EM&gt;. &lt;BR&gt;Now, depending on the number of &lt;EM&gt;PivotItems&lt;/EM&gt; or the size of the header’s text, you may not see your target &lt;EM&gt;Header&lt;/EM&gt; : you need another way to switch pages.&lt;/P&gt;
&lt;P&gt;You probably expect the &lt;EM&gt;PivotControl&lt;/EM&gt; to support flicking directly inside the &lt;EM&gt;PivotItem&lt;/EM&gt;. Well, that’s what it does ! Flick left, flick right, flick through the end and cycle back to where you started.&lt;/P&gt;
&lt;P&gt;I am aware of at least one animation bug in the current implementation. I’m still tracking it down, and will follow through every bug report you file &lt;A href="http://phone.codeplex.com/workitem/list/basic" mce_href="http://phone.codeplex.com/workitem/list/basic"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;H3&gt;Sample WeatherForecast application&lt;/H3&gt;
&lt;P&gt;The screen captures in this blog post are from a sample application i’m building called WeatherForecast. As its name suggests this is a weather forecasting application (what a surprise !).&lt;/P&gt;
&lt;P&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: block; FLOAT: none; MARGIN-LEFT: auto; BORDER-TOP: 0px; MARGIN-RIGHT: auto; BORDER-RIGHT: 0px" title=weather_app border=0 alt=weather_app src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PivotControlsample_1043F/weather_app_3.png" width=480 height=307 mce_src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PivotControlsample_1043F/weather_app_thumb.png"&gt; &lt;/P&gt;
&lt;P&gt;I chose to build a weather forecasting app as a sample, because it is a concept that everyone understands and it allows me to create &lt;EM&gt;PivotItems&lt;/EM&gt; dynamically. Right now, the application is incomplete and only shows fake data. But i do plan to complete it shortly, and will write a series of blog posts as a tutorial for writing a Windows Phone 7 app using the &lt;EM&gt;PivotControl&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;On a side note, the weather web services i’m using are from &lt;A href="http://www.worldweatheronline.com/" mce_href="http://www.worldweatheronline.com/"&gt;World Weather Online, weather forecast and weather content provider&lt;/A&gt;. I think that their weather icons blend quite smoothly with the Metro design language. &lt;BR&gt;Go to their web site to request a API Key, if you want to call their services.&lt;/P&gt;
&lt;H3&gt;What’s next ?&lt;/H3&gt;
&lt;UL&gt;
&lt;LI&gt;I haven’t had much time to debug the &lt;EM&gt;PivotControl&lt;/EM&gt; yet. As a consequence, i do expect a number of UI or reliability bugs to pop-up. If you find a bug, please make sure you file it &lt;A href="http://phone.codeplex.com/workitem/list/basic" mce_href="http://phone.codeplex.com/workitem/list/basic"&gt;here&lt;/A&gt;. If you find a workaround or manage to fix it somehow, also make sure that you share the information in your bug report as well. &lt;/LI&gt;
&lt;LI&gt;I’ve had lots of fun writing these controls, and will continue the effort. If you find them useful, please let me know by sending me an email or dropping a comment below. Also send me a link to your project, i’m really excited to see what type of apps you guys will be building with these controls. &lt;/LI&gt;
&lt;LI&gt;Again, these controls aren’t the official Microsoft Panorama and Pivot controls. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;In case you’ve missed it, here’s the link to the &lt;A href="http://phone.codeplex.com/" mce_href="http://phone.codeplex.com/"&gt;Windows Phone 7 Panorama &amp;amp; Pivot controls&lt;/A&gt; sample projects.&lt;/P&gt;
&lt;P&gt;Cheers &lt;BR&gt;-stephane&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10009909" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/stephanc/archive/tags/Windows+Phone+7/">Windows Phone 7</category><category domain="http://blogs.msdn.com/b/stephanc/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/stephanc/archive/tags/Pivot/">Pivot</category></item><item><title>Update to the Panorama Control for Windows Phone</title><link>http://blogs.msdn.com/b/stephanc/archive/2010/05/04/update-to-the-panorama-control-for-windows-phone.aspx</link><pubDate>Tue, 04 May 2010 21:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10007370</guid><dc:creator>Stephane Crozatier</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/stephanc/rsscomments.aspx?WeblogPostID=10007370</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/stephanc/commentapi.aspx?WeblogPostID=10007370</wfw:comment><comments>http://blogs.msdn.com/b/stephanc/archive/2010/05/04/update-to-the-panorama-control-for-windows-phone.aspx#comments</comments><description>&lt;P&gt;I’ve been busy with work during the past few weeks, so i haven’t had time to work on Windows Phone as much as i wanted…&lt;/P&gt;
&lt;P&gt;Anyhow, i just wanted to give you a quick heads-up on the &lt;A href="http://phone.codeplex.com/" mce_href="http://phone.codeplex.com/"&gt;lastest drop&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;I took some time this week-end to update the control code, fix some bugs, implement few change requests, and prepare for the next milestone.&lt;/P&gt;
&lt;P&gt;I have also completely rewritten the &lt;EM&gt;PictureViewer &lt;/EM&gt;sample code to drop the dependency on the &lt;A href="http://silverlight.codeplex.com/" mce_href="http://silverlight.codeplex.com/"&gt;Silverlight Toolkit&lt;/A&gt;. I realized that many developers, like me, aren’t familiar with the entire Silverlight ecosystem. And for that reason, they may find it challenging to install/run sample projects that have external dependencies. &lt;BR&gt;Because i still wanted to use some kind of &lt;A href="http://silverlight.codeplex.com/wikipage?title=Silverlight%20Toolkit%20Control%20Overview%20Pg5&amp;amp;referringTitle=Home" mce_href="http://silverlight.codeplex.com/wikipage?title=Silverlight%20Toolkit%20Control%20Overview%20Pg5&amp;amp;referringTitle=Home"&gt;WrapPanel&lt;/A&gt; to show the pictures in a vertical container (and track &lt;A href="http://phone.codeplex.com/WorkItem/View.aspx?WorkItemId=5708" mce_href="http://phone.codeplex.com/WorkItem/View.aspx?WorkItemId=5708"&gt;vertical manipulations&lt;/A&gt;), I ended-up writing a very simple panel substitute. I got to discover &lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.measureoverride(VS.95).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.measureoverride(VS.95).aspx"&gt;MeasureOverride&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.arrangeoverride(VS.95).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.arrangeoverride(VS.95).aspx"&gt;ArrangeOverride&lt;/A&gt; in the process, which was a great learning opportunity.&lt;/P&gt;
&lt;P&gt;The &lt;EM&gt;PictureViewer&lt;/EM&gt; sample is a dummy picture viewer application (duh!). It downloads the latest &lt;A href="http://www.bing.com/" mce_href="http://www.bing.com"&gt;Bing&lt;/A&gt; background images to the device’s &lt;A href="http://msdn.microsoft.com/en-us/library/ff402541.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ff402541.aspx"&gt;Isolated Storage&lt;/A&gt;, and show them (tile view) inside the &lt;EM&gt;Panorama Control&lt;/EM&gt; and also (full view) inside a dedicated application page.&lt;/P&gt;
&lt;P&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: block; FLOAT: none; MARGIN-LEFT: auto; BORDER-TOP: 0px; MARGIN-RIGHT: auto; BORDER-RIGHT: 0px" title=pictureviewerapp border=0 alt=pictureviewerapp src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/UpdatetothePanoramaControlforWindowsPhon_143AA/pictureviewerapp_3.png" width=510 height=480 mce_src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/UpdatetothePanoramaControlforWindowsPhon_143AA/pictureviewerapp_thumb.png"&gt; &lt;BR&gt;As i wrote the code for this sample, i got to learn more about Silverlight/.Net. So i hope that i’ve made smarter coding decisions this time around. I’m still not happy with several details (the Async download implementation for one), but that’s part of the learning process...&lt;/P&gt;
&lt;P&gt;While writing the PictureViewer application, i got to learn and use the following features :&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://www.silverlight.net/learn/videos/all/windows-phone-silverlight-navigation/" mce_href="http://www.silverlight.net/learn/videos/all/windows-phone-silverlight-navigation/"&gt;Navigation Framework&lt;/A&gt; for moving to/from different pages in the application &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.95).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.95).aspx"&gt;WebClient class&lt;/A&gt; and async downloading documents thru HTTP. &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/182eeyhh.aspx" mce_href="http://msdn.microsoft.com/en-us/library/182eeyhh.aspx"&gt;XML Serialization&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlelementattribute.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlelementattribute.aspx"&gt;XMLElement attribute&lt;/A&gt; to &lt;A href="http://msdn.microsoft.com/en-us/library/fa420a9y.aspx" mce_href="http://msdn.microsoft.com/en-us/library/fa420a9y.aspx"&gt;read&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/szzyf24s.aspx" mce_href="http://msdn.microsoft.com/en-us/library/szzyf24s.aspx"&gt;persist&lt;/A&gt; structured data. &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb387063.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb387063.aspx"&gt;LINQ to XML&lt;/A&gt; to read/write arbitrary XML data. &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/ff402541.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ff402541.aspx"&gt;Isolated Storage&lt;/A&gt; to persist data (binary and XML) &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;If you are developing an application with one of the features above and you’re looking for examples, feel free to download the code and peek around. If you are already familiar with those, well … you can always download the latest &lt;EM&gt;Panorama Control&lt;/EM&gt; drop and have fun with it. &lt;BR&gt;Head over to &lt;A href="http://phone.codeplex.com/" mce_href="http://phone.codeplex.com"&gt;http://phone.codeplex.com&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;By the way, i’ve started to work on a &lt;FONT color=#ff0000&gt;&lt;STRONG&gt;Pivot Control&lt;/STRONG&gt; &lt;/FONT&gt;implementation based on the same concepts i used for the &lt;EM&gt;Panorama Control&lt;/EM&gt;. I’m not sure when i’ll publish it (perhaps in 1 or 2 weeks) as i have higher tasks in my priority list right now.&lt;/P&gt;
&lt;P&gt;I’m also interested in having your feedbacks on missing controls that i can put together. I’m thinking a ComboBox that adheres to the Metro UI design language, but i’m sure that you have other ideas. Feel free to drop a note in the comments.&lt;/P&gt;
&lt;P&gt;Stay tuned for more, and remember : this is by no means a Microsoft supported and official project, i’m just a guy trying to learn Silverlight on the Phone. Please use the official controls if/when they are released.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10007370" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/stephanc/archive/tags/Windows+Phone+7/">Windows Phone 7</category><category domain="http://blogs.msdn.com/b/stephanc/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/stephanc/archive/tags/Panorama/">Panorama</category><category domain="http://blogs.msdn.com/b/stephanc/archive/tags/Isolated+Storage/">Isolated Storage</category><category domain="http://blogs.msdn.com/b/stephanc/archive/tags/LINQ/">LINQ</category><category domain="http://blogs.msdn.com/b/stephanc/archive/tags/XML/">XML</category></item><item><title>Windows Phone 7 Panorama Control sample</title><link>http://blogs.msdn.com/b/stephanc/archive/2010/04/04/windows-phone-7-panorama-control-sample.aspx</link><pubDate>Sun, 04 Apr 2010 20:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9990340</guid><dc:creator>Stephane Crozatier</dc:creator><slash:comments>10</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/stephanc/rsscomments.aspx?WeblogPostID=9990340</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/stephanc/commentapi.aspx?WeblogPostID=9990340</wfw:comment><comments>http://blogs.msdn.com/b/stephanc/archive/2010/04/04/windows-phone-7-panorama-control-sample.aspx#comments</comments><description>&lt;P&gt;What a great time to be a .Net developer !&lt;/P&gt;
&lt;P&gt;Like many, i’ve been following the &lt;A href="http://live.visitmix.com/" mce_href="http://live.visitmix.com"&gt;announcements on Windows Phone 7 Series&lt;/A&gt;. I’ve installed &lt;A href="http://go.microsoft.com/?linkid=9713250" mce_href="http://go.microsoft.com/?linkid=9713250"&gt;the tools&lt;/A&gt;, played with the emulator and ported some experimental XNA code i had written for my Zune HD. &lt;BR&gt;I have to say that i’m really impressed by what the team have achieved during the past months. Okay, there are few things missing here and there (local relational database, low priority background tasks, …). But remember, what we see is still an early CTP. Anyways, the &lt;A href="http://msdn.microsoft.com/en-us/library/ff402531(VS.92).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ff402531(VS.92).aspx"&gt;overall developer platform&lt;/A&gt; looks really promising and i was so excited, to the point that i’ve decided to learn Silverlight.&lt;/P&gt;
&lt;P&gt;Yeah, i’ve been talking about Silverlight for a while but never coded anything beyond hello world apps, until now… I never took the time to sit down and see how my old GDI skills could be migrated over. Well, after few hours of reading and playing around, i have to say that i was really surprised by how fast one could ramp-up and get things going with Silverlight. I think that the quality of the tools and the all the information available through the community really helped out.&lt;/P&gt;
&lt;P&gt;While experimenting with the &lt;A href="http://msdn.microsoft.com/en-us/library/ff402535(VS.92).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ff402535(VS.92).aspx"&gt;Windows Phone 7 Series CTP SDK&lt;/A&gt;, i noticed some things are missing. In particular, i wished there were more high-level UI controls to help developers build apps that look and feel consistent on the platform. &lt;BR&gt;Since i’m getting started with Silverlight, i’m thinking “What’s the best way to learn a UI technology ? Let’s build a control !”.&lt;/P&gt;
&lt;P&gt;So i give you my first Silverlight control : a &lt;A href="http://phone.codeplex.com/" mce_href="http://phone.codeplex.com"&gt;Panorama control for Windows Phone 7 Series&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: block; FLOAT: none; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; MARGIN-LEFT: auto; BORDER-LEFT-WIDTH: 0px; MARGIN-RIGHT: auto" title=panorama-ctrl border=0 alt=panorama-ctrl src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PanoramaControl_FF66/panorama-ctrl_3.jpg" width=611 height=480 mce_src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PanoramaControl_FF66/panorama-ctrl_3.jpg"&gt; &lt;/P&gt;
&lt;H3&gt;The control&lt;/H3&gt;
&lt;P&gt;We’ve all seen the “Hub experience” in action. However, i’d like to encourage every Windows Phone 7 Series developer to read the &lt;A href="http://windowsteamblog.com/blogs/wpdev/archive/2010/03/18/windows-phone-7-series-ui-design-amp-interaction-guide.aspx" mce_href="http://windowsteamblog.com/blogs/wpdev/archive/2010/03/18/windows-phone-7-series-ui-design-amp-interaction-guide.aspx"&gt;preview UI Design &amp;amp; Interaction Guide&lt;/A&gt; (also available &lt;A href="http://download.microsoft.com/download/D/8/6/D869941E-455D-4882-A6B8-0DBCAA6AF2D4/UI%20Design%20and%20Interaction%20Guide%20for%20Windows%20Phone%207%20Series.pdf" mce_href="http://download.microsoft.com/download/D/8/6/D869941E-455D-4882-A6B8-0DBCAA6AF2D4/UI%20Design%20and%20Interaction%20Guide%20for%20Windows%20Phone%207%20Series.pdf"&gt;here&lt;/A&gt;). This is a guidance on how to design great Windows Phone apps, it goes into great length at describing some design guidelines for the phone. It’s also a great place to learn about the Metro design. It is still a preview document and i do expect some future updates.&lt;/P&gt;
&lt;P&gt;My motivation for building this control was two-fold : (1) to learn Silverlight as i said earlier, and (2) because existing examples of a panoramic apps or controls out there don’t mimic the behavior described in the &lt;A href="http://download.microsoft.com/download/D/8/6/D869941E-455D-4882-A6B8-0DBCAA6AF2D4/UI%20Design%20and%20Interaction%20Guide%20for%20Windows%20Phone%207%20Series.pdf" mce_href="http://download.microsoft.com/download/D/8/6/D869941E-455D-4882-A6B8-0DBCAA6AF2D4/UI%20Design%20and%20Interaction%20Guide%20for%20Windows%20Phone%207%20Series.pdf"&gt;Design &amp;amp; Interaction Guide&lt;/A&gt; described above (in particular, the UI is supposed to wrap-off when panning past the end of the picture).&lt;/P&gt;
&lt;P&gt;The &lt;EM&gt;PanoramaControl&lt;/EM&gt; control itself is pretty basic.&lt;/P&gt;
&lt;P&gt;It implements a &lt;EM&gt;Title&lt;/EM&gt; and &lt;EM&gt;BackgroundImage&lt;/EM&gt; dependent properties. It also derives from ItemsControl, just like a tab control would. Each individual Item is of type &lt;EM&gt;PanoramaItem&lt;/EM&gt;, you can think of these as visual sections. Each section can use the default &lt;EM&gt;Width&lt;/EM&gt; provided by the control, or specify a custom &lt;EM&gt;Width&lt;/EM&gt; if you need more space. The &lt;EM&gt;Header&lt;/EM&gt; and &lt;EM&gt;Content&lt;/EM&gt; properties must be assigned for each &lt;EM&gt;PanoramaItem&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: block; FLOAT: none; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; MARGIN-LEFT: auto; BORDER-LEFT-WIDTH: 0px; MARGIN-RIGHT: auto" title=panorama-ctrl-layout border=0 alt=panorama-ctrl-layout src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PanoramaControl_FF66/panorama-ctrl-layout_3.jpg" width=611 height=480 mce_src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PanoramaControl_FF66/panorama-ctrl-layout_3.jpg"&gt; &lt;/P&gt;
&lt;H3&gt;Using the control &lt;/H3&gt;
&lt;P&gt;Right now, the design-time experience for this control is not “great” but it is pretty much okay. I don’t know how to allow the developer to switch the active &lt;EM&gt;PanoramaItem&lt;/EM&gt; during design-time. I’ll discuss with some folks or look at other controls implementations to find-out and fix this in some future releases.&lt;/P&gt;
&lt;P&gt;So let’s look at how you would instantiate and populate the control in XAML, which i think is the most common case:&lt;/P&gt;
&lt;P&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: block; FLOAT: none; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; MARGIN-LEFT: auto; BORDER-LEFT-WIDTH: 0px; MARGIN-RIGHT: auto" title=panorama-ctrl-xaml border=0 alt=panorama-ctrl-xaml src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PanoramaControl_FF66/panorama-ctrl-xaml_3.png" width=644 height=580 mce_src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PanoramaControl_FF66/panorama-ctrl-xaml_3.png"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;Navigation&lt;/H3&gt;
&lt;P&gt;Like you would expect, the control supports &lt;EM&gt;Pan&lt;/EM&gt; and &lt;EM&gt;Flick&lt;/EM&gt; for moving between sections.&lt;/P&gt;
&lt;P&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; MARGIN-LEFT: 0px; BORDER-LEFT-WIDTH: 0px; MARGIN-RIGHT: 0px" title=panorama-panflick border=0 alt=panorama-panflick src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PanoramaControl_FF66/panorama-panflick_3.png" width=240 height=99 mce_src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PanoramaControl_FF66/panorama-panflick_3.png"&gt; &lt;/P&gt;
&lt;P&gt;It also has a feature that snaps the viewbox to the closest section’s edge (left or right). I haven’t seen anything about snapping in the &lt;A href="http://download.microsoft.com/download/D/8/6/D869941E-455D-4882-A6B8-0DBCAA6AF2D4/UI%20Design%20and%20Interaction%20Guide%20for%20Windows%20Phone%207%20Series.pdf" mce_href="http://download.microsoft.com/download/D/8/6/D869941E-455D-4882-A6B8-0DBCAA6AF2D4/UI%20Design%20and%20Interaction%20Guide%20for%20Windows%20Phone%207%20Series.pdf"&gt;Design Guide&lt;/A&gt;, however i figured it is convenient so i’ve decided to implement it. You can choose not to snap the sections by setting the &lt;EM&gt;AutoSnap&lt;/EM&gt; property to &lt;EM&gt;False&lt;/EM&gt; on the &lt;EM&gt;PanoramaItem&lt;/EM&gt;, although this only makes sense for longer sections.&lt;/P&gt;
&lt;P&gt;While implementing the &lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.onmanipulationstarted(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.onmanipulationstarted(VS.100).aspx"&gt;OnManipulationStarted&lt;/A&gt; / &lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.onmanipulationdelta(v=VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.onmanipulationdelta(v=VS.100).aspx"&gt;OnManipulationDelta&lt;/A&gt; / &lt;A href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.onmanipulationcompleted(v=VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.onmanipulationcompleted(v=VS.100).aspx"&gt;OnManipulationCompleted&lt;/A&gt; overrides, i ran into an issue where the manipulation event is captured by a child control first (higher up in the visual tree before the &lt;EM&gt;PanoramaControl&lt;/EM&gt; receives the notification). In such case, the child control will trigger the event regardless of my decision to handle it or not : for example, a button may trigger the “Click” event while you flick the &lt;EM&gt;PanoramaControl&lt;/EM&gt;. &lt;BR&gt;This is best described in the &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/98ef9058-5d7f-4218-9364-2fe1dcefdb16" mce_href="http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/98ef9058-5d7f-4218-9364-2fe1dcefdb16"&gt;following forum posting&lt;/A&gt;, with a workaround suggestion by &lt;A href="http://blogs.msdn.com/ptorr" mce_href="http://blogs.msdn.com/ptorr"&gt;Peter Torr&lt;/A&gt;. I did try this approach, couldn’t make it work for some reason so i’ve implemented another workaround that i’m ashamed to describe here. I sure hope to find a better solution for this in future releases.&lt;/P&gt;
&lt;P&gt;Navigation and user interaction is an area in particular where i think the emulator is not sufficient for testing. The form factor, and especially the touch feedbacks, finger size, distances, …, are different in the emulator and the real device. But well… I don’t have a device, so i can’t comment further…&lt;/P&gt;
&lt;P&gt;As you may see in the code, i did implement keyboard events for navigation as well (up, down, left, right). Not that i expect the control to be used with the phone keyboard, but this just helped so much during testing outside of the emulator. &lt;BR&gt;Yes, i’ve done most of my tests in plain-Silverlight through the Web Browser (i do provide a browser Silverlight sample as well). And i, for one, can testify that the runtimes are very-very similar from desktop Silverlight to the phone implementation. Of course, you’ll see the obvious differences related to phone specific features. But overall, the developer experience is pretty much the same. What a great time to be a .Net developer ! &lt;BR&gt;&lt;/P&gt;
&lt;H3&gt;Templates and styles&lt;/H3&gt;
&lt;P&gt;Well, this was the most tricky area for me as i am discovering Silverlight, coming from a Win32/GDI background. WPF and Silverlight designers like to change the appearance of controls layouts by overriding the controls templates.&lt;/P&gt;
&lt;P&gt;For example, with the default style provided by the control, the &lt;EM&gt;Title&lt;/EM&gt; is just a plain TextBlock. What if you wanted to add a logo image before the title, but still wanted to make it stick to the title and scroll at the same speed ? &lt;BR&gt;A common approach with other controls, i believe, would be to replace the &lt;EM&gt;Title&lt;/EM&gt;’s template. So i’d better make sure you could change templates with this &lt;EM&gt;PanoramaControl&lt;/EM&gt; as well.&lt;/P&gt;
&lt;P&gt;As shown in the Expression Blend screen capture below, the &lt;EM&gt;PanoramaControl&lt;/EM&gt; provides templates for the &lt;EM&gt;ItemsPanel&lt;/EM&gt;, &lt;EM&gt;BackgroundImage&lt;/EM&gt; and &lt;EM&gt;Title&lt;/EM&gt;. The &lt;EM&gt;PanoramaItem&lt;/EM&gt; is also templated, although i haven’t merged its template with the &lt;EM&gt;PanoramaControl&lt;/EM&gt; default style yet. &lt;BR&gt;I am lacking experience in this area, and am still looking for the best approach (single and common template for all Items or allowing each Item to have its own template). So i’ve decided to take the “we’ll see later” approach…&lt;/P&gt;
&lt;P&gt;I’m sure lots of folks out there have been through this, and i’ll be happy to hear your advice here as well.&lt;/P&gt;
&lt;P&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; MARGIN-LEFT: 0px; BORDER-LEFT-WIDTH: 0px; MARGIN-RIGHT: 0px" title=panorama.ctrl-templates border=0 alt=panorama.ctrl-templates src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PanoramaControl_FF66/panorama.ctrl-templates_3.png" width=512 height=211 mce_src="http://blogs.msdn.com/blogfiles/stephanc/WindowsLiveWriter/WindowsPhone7PanoramaControl_FF66/panorama.ctrl-templates_3.png"&gt; &lt;BR&gt;&lt;/P&gt;
&lt;H3&gt;Disclaimer&lt;/H3&gt;
&lt;UL&gt;
&lt;LI&gt;I’m not on the Windows Phone team. This is not the official control, and i don’t know if they have plans for such controls in the future. The &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/2892a6f0-ab26-48d6-b63c-e38f62eda3b3" mce_href="http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/2892a6f0-ab26-48d6-b63c-e38f62eda3b3"&gt;developer FAQ&lt;/A&gt; seems to suggest something may be coming down the road. &lt;/LI&gt;
&lt;LI&gt;This is not production code. I am using it as a learning experience for Silverlight, which i’ve started less than 2 weeks ago. I’m still learning about the technology and writing controls : there are lots of areas for improvements in the current implementation (quality and robustness, templates and customization, resource usage, fonts, themes, …).&lt;/LI&gt;
&lt;LI&gt;This is a pet project i’m working on during my free time, just for fun. For now there’s no plan to turn it into something more than a pet project, although i’d like to continue the effort and perhaps build something i will call the Pivot control.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Again, here’s the link to the &lt;A href="http://phone.codeplex.com/" mce_href="http://phone.codeplex.com"&gt;sample Panorama control for Windows Phone 7 Series&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Have fun playing with the control, and do leave some feedback if you like (or dislike) it ! &lt;BR&gt;&lt;BR&gt;-stephane&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9990340" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/stephanc/archive/tags/Windows+Phone+7/">Windows Phone 7</category><category domain="http://blogs.msdn.com/b/stephanc/archive/tags/Silverlight/">Silverlight</category><category domain="http://blogs.msdn.com/b/stephanc/archive/tags/Panorama/">Panorama</category></item></channel></rss>