This week I attended a WP7 boot camp and was reminded that the phone has more than one orientation. The instructor did a Hello Phone application and should that the default behaviour is a single orientation, Portrait. She then went on to explain that with a bit of code, landscape can be supported. Actually, it is even easier than that. In the XAML is the keyword SupportedOrientations. Select the value for the keyword and hit a letter. Thanks to IntelliSense, Visual Studio will give you a choice of three options: Portrait, Landscape or PortraitOrLandscape. Just chosing the last option will allow you app to switch based on orientation. If you let XAML do the heavy lifting, that may be all you have to do. The screen will snap when the orientation is changed, but transitions are something you can easily add to the XAML. The key thing to remember is not to hard code widths, let XAML adjust the display as the width changes.
So with a little code behind and XAML you can do some fancy things with your app. Unfortunately, that is where a lot of developers stop.
Are you aware that there are three not two orientations and they can be detected in code? Actually, there should be four, but for some reason Microsoft decided not to implement it. So, in addition to Portrait, there are TWO landscape modes, Landscape Left and Landscape Right (or you could call them Landscape and Upside down Landscape). The missing one is Upside down Portrait, which I think would be interesting.
So, two landscapes, big deal. Built in to WP7 is an app that demonstrates one of the possibilities that this extra orientation can give, the Calculator. In portrait orientation, it is a simple calculator. Turn it to lanscape and you have a scientific calculator. turn it 180 degrees and now you have a programmer’s calculator. So in addition to changing the position of items in the layout as you rotate the phone, your app could provide a different experience depending on one of the three orientations. What about a skiing game when in Portrait, flying game when in landscape left and a swimming game when in landscape right? Of course, you will have to limit your game experience to being less than a 45 degree rotation of the phone if you want to stay on that layout, but then that could mean some interesting transitions.
John Marshall… Visio MVP Visio.MVPs.org
I like what you said about devs HAVE to remember NOT to hard code heights/widths. Pick an appropriate layout (maybe even requires some nesting) and then use Auto and *. It’s a bit more work up front, but once it’s done, you can EASILY migrate the UI to a tablet even, IF you do this part correctly. Do it wrong……and you’ll be embarassed when things go big. DOH!
re different orientations
I actually wish Microsoft HAD implemented the “upside down portrait” mode (extending your terms, I like those). The idea is playing games, I’m FOREVER pressing one of the buttons at the bottom and it drives me NUTS! Turn the phone upside down, and you’re good to go. But that’s not supported…..yet!
re different experiences for the different orientations
I wrote a blog about this (using just code, xaml and code, and just xaml) for this type fo thing. Maybe your readers might be interested. Shameless plug? Maybe, sorry, but it is applicable IMHO.
http://www.pchenry.com/Home/tabid/36/EntryId/467/How-do-you-rotate-your-pages-in-WP7.aspx
Good blog! So what are YOU going to implement now that you have a new tool in your toolchest?