User Interface from Windows Phone to Windows 8
Join the DZone community and get the full member experience.Join For Free
in this article i want to expand on the information already available about porting user interfaces from windows phone to windows 8. the most important place to start is an article titled porting silverlight or wpf xaml/code to a metro style app on msdn. it covers slight changes in the application object, window object and navigation system. it also covers more involved changes to the resource model and to touch. i’ll talk briefly about touch at the end of this post and i’m dedicating an entire article to resources (hyperlink here when it’s done). if you haven’t done so yet, consider switching over to the official guide and coming back here when you’re done.
one of the biggest adaptations developers needed to make coming from any other platform to windows phone was learning to use the metro design language in an effective way. if you’ve already built a successful windows phone app, chances are you’ve already made this change. still, there are new and unique guidelines for windows 8 apps that you need to become familiar with. in fact there are guidelines for things you might not have thought about having guidelines for, like drag and drop and edge-based animations.
these guidelines exist to make the windows 8 experience consistent from application to application, which is important because consistency builds confidence for users. luckily a good chunk of the work is already done for you simply by leveraging the built-in controls. even if you’re creating highly customized content or your own controls, winrt makes it easy to fit in by providing standardized animations and transitions right out of the box.
to learn more about the standardized animations and transitions see quickstart: animating your ui . for tons of great metro guidance see making great metro style apps , ux guidelines for metro style apps and design.windows.com .
windows 8 of course has all the basic controls you’re used to like button, checkbox, listbox, etc. as you may have heard, though, the namespaces are a little different. for the most part, simply changing references from system.windows to windows.ui.xaml will get most of the basic tags working. but since we’re on the topic of namespaces, it’s important to note that the namespace syntax itself has changed.
here’s the old syntax:
and here’s the new one:
not only is the new syntax simpler, but it leaves all of the assembly management to the underlying framework. this change does impact how you create things like strings though, so i highly recommend you read porting silverlight or wpf xaml/code to a metro style app for more details.
you might be surprised to learn that windows 8 does not include the panorama or pivot controls from windows phone. keep in mind those controls were created to deal with small screen real estate, which isn’t much of a problem on slates and desktop monitors. it’s vitally important to make good use of all the screen real estate available and the new semanticzoom flipview and gridview controls can help you accomplish this. though flipview could potentially be used to create sliding panels similar to a panorama, don’t get caught up in trying to port your phone experience as-is. instead, spend plenty of time playing with windows 8 applications and understand the new controls. a gridview combined with semanticzoom can offer a better experience on a larger screen than a panorama would.
in my opinion, one of the most aesthetically pleasing apps in marketplace right now is flixster. not all of the features from windows phone made it into the current demo, and it doesn’t currently use semanticzoom, but i think it shows a good migration from panorama to the new windows 8 style.
m-v-vm, data and portability
“oh no!” you say, “now that there are new controls all of my ui code has to change!” not true if you’ve been following the popular m-v-vm pattern. m-v-vm allows you to separate the underlying business logic from what’s displayed on the screen. with m-v-vm there’s a viewmodel that provides data and commands that the view can bind to. if you’ve already done the work to put m-v-vm in place, your xaml will change but the underlying viewmodel may not have to change at all.
there are other interesting tricks you can employ to share code with windows phone. for example, visual studio 11 has the new portable library project which allows you to create dlls that can be referenced and used in both projects.
if you haven’t been using m-v-vm or if you’d like to learn more about these techniques, be sure to read improving maintainability . to learn more about data binding in windows 8 (including grouping for gridview and semanticzoom) see the article data binding with xaml and the xaml data binding sample .
|note: there’s currently a bug in consumer preview with data binding to observablecollection<t>. the xaml data binding sample provides a workaround.|
the windows 8 appbar feels similar to the windows phone application bar, but there have been several improvements. one of the improvements i’m quite happy to see is support for data binding. i mentioned commands as part of the m-v-vm pattern above. in the current windows phone sdk there’s no way to bind appbar buttons to m-v-vm commands, but in windows 8 you can.
windows 8 will run on a wide range of devices so user interfaces need to scale. because of this need to scale, vector graphics are preferred for iconography over bitmap images. (winrt has mechanisms for scaling bitmaps beautifully too, which i’ll talk about below.) with scalability in mind, the windows team did something i think is very cool: they embedded the most common appbar icons in a font called sego ui symbol . font scaling works very well for this purpose, and if you drop an appbarbutton onto the art board and change its scale (transform panel) you’ll see what i mean.
unfortunately there isn’t currently an easy way to choose icons from the font using blend or visual studio, but there are a few tricks. first, you can run character map and select sego ui symbol . once selected, scroll down to the bottom and you’ll see the icons.
click the ‘icon’ you want, click s elect and then c opy. the ‘icon’ is then placed on the clipboard, ready to be pasted it into any button (or text block) that’s using sego ui symbol .
|tip: to run the character map tool, from the start experience just start typing the word “character”. the start experience will automatically switch to ‘all applications’ mode and begin filtering the list on what you type.|
now to make things a little easier on developers, visual studio includes a file in every project called standardstyles.xaml . this file has within it a number of predefined button styles that are setup to use these icons. blend allows you to drag these styles out from the asset panel to automatically create a button with the style already applied. so, for example, if we wanted to create a help button we could drag out the following:
it turns out that sego ui symbol includes around 150 icons, but standardstyles.xaml currently shipping with visual studio only includes styles for 29. you can either edit the style and use the character map trick above, or you can download an updated standardstyles from tim heuer. his awesome blog post xaml appbar button styles for windows 8 covers this topic and using these styles in even more depth.
150 icons is great, but what if you don’t find the icon you’re looking for? don’t worry because there are several other really great options remaining. one of my favorites is the awesome metro studio package by syncfusion.
this package includes over 600 metro style icons and gives you unprecedented control over their presentation. you can change the background type (none, square, outlined circle, filled circle), the padding, the background color, icon color and even the size. you can export the customized icon as .png , but even better you can copy the customized icon as a scalable xaml ready to be pasted into your applications resource dictionary. how much does this incredibly cool package cost? $0.00. yup, free. just drop ‘em a note to say thanks on twitter , facebook or google+ .
okay, so that’s 750+ icons. but what if you still can’t find what you’re looking for? well, there are plenty of other icon packs (just search for metro icons ) and you can always create exactly what you need using expression design, adobe illustrator or my new favorite inkscape .
inkscape is free, open source, and can save as scalable xaml natively.
windows 8 supports a wide range of devices with varying resolutions and dpis (dots per inch). this is different from windows phone which today supports only one resolution. those who have written apps for android might know what a challenge this can be, but fear not! once again winrt does most of the heavy lifting for you.
first, windows 8 supports viewbox, just like windows phone, which is great for games and fixed-layout interfaces. on the other hand, gridview and grid are great tools for creating flexible layouts. something you might not expect is that even in flow layouts, windows automatically increases the scale of some ui elements as the dpi goes up. this automatic scaling makes sure that items like buttons and sliders are just as easy to grab with your finger at 260 dpi as they are at 130. this scaling, however, does not happen continuously across the full range of dpis. scaling only happens at certain thresholds. this is because apps still use bitmap images and bitmaps don’t tend to look great when they’re scaled to arbitrary sizes.
from the building windows 8 blog post scaling to different screens
the scaling thresholds are set at 140% and 180% of the baseline resolution 1366 x 768. when these thresholds are reached, vector graphics inside ‘auto-scale’ elements are automatically scaled too. but what about bitmap images? well, the winrt resource system is smart and it will look for higher resolution images (based on a naming convention ) to be automatically swapped in when the scale changes. the key takeaway, for me at least, is to design at 1366 x 768 and use the platform tab in blend and the simulator to test designs at all resolutions and dpis. at the very high end of the scale, it’s probably also prudent to consider modifying layout or swapping in different data templates to make the best use of the space.
more than anything i highly recommend the excellent article scaling to different screens on the building windows 8 blog. it covers everything i covered here in far greater detail and it gives an inside peek at the factors that lead to this design. i really did find it fascinating. guidelines for scaling to pixel density and guidelines for scaling to screens are two other excellent references that cover naming conventions, fixed and flex layouts as well as general “do’s” and “don’ts”.
windows phone developers are used to having the entire screen available for their app. even system dialogs like phone calls and toasts appear on top of the application and don’t change available real estate. a windows phone developer today can design a user interface at 480 x 800 and expect it will work across all windows phones (though microsoft has always reserved the right to add additional resolutions at some point).
in addition to supporting a much broader range of screen sizes and resolutions, windows 8 applications are also required to support two new view states: “snapped” and “filled”.
in the screenshot above, cut the rope is running “filled” and music is running “snapped”. these two new states are what allow two normally full-screen applications to run side-by-side and share the screen.
it’s very important to point out here that the music app looks quite different in snapped mode then it does in full screen. the rows of album art and the large track bar have been replaced with a small and concise listing of tracks. this fairly radical change allows the music app to remain highly useful even with small amount of space it has. it’s no surprise that users will expect this type of behavior from your apps too.
if all this sounds daunting, you’re not alone. when i first read about the filled and snapped states my head was filled with visions of user controls, xaml hacking and showing and hiding things in code. thankfully, i couldn’t have been further from the truth.
many windows phone apps today support landscape since we basically get it for free. some of the more advanced apps are even using the visual state manager to switch to a customized layout that looks better in landscape mode. this same trick can be used for “snapped” and “filled”, and the visual studio templates help you do exactly that out of the box.
|note: an introduction to the visual state manager is outside the scope of this article, but if you’ve never used or seen it before i recommend you check out the article and accompanying video creating control skins with visual state manager on christian schormans blog.|
whenever you create a new project, visual studio automatically adds a file under the common folder called layoutawarepage.cs . layoutawarepage inherits from page and adds four new visual states to itself:
as you can see, the visual states correspond to the four possible view states that your app can be in at any given time. using the visual state manager you can show, hide or change virtually any property of any element on the art board and those changes will only be applied when your app is running in that state.
for example, let’s take a look at groupeditemspage (part of the ‘grid application’ template included with visual studio). here groupeditemspage is in the fullscreenlandscape state (click for larger view):
and here it is in snapped state:
this works because the page actually has both a gridview and a listview on it at all times. when the visual state changes, one control is hidden and the other is shown (accomplished by changing the visibility property).
i’d like to pause and point out that in the ‘snapped’ screenshot above, the app still looks like its filling the whole screen. that’s because the visual state manager and the platform tab aren’t currently wired together in blend. in other words, telling blend that you want to see what the page will look like when viewed snapped on a 10” slate doesn’t automatically trigger the visual state manager to switch to the snapped state. (remember, this is automatic switching is handled at runtime by layoutawarepage which blend knows nothing about). so, to properly preview your designs in blend you should set the correct view on the platform tab:
and set the corresponding state on the states tab. when they’re both in sync, the art board should show what you’d expect to see at runtime on that device (assuming you’ve got design-time data).
i dedicated the second post in this series to a step-by-step example of using this technique. see view states using visual state manager . and for more info see designing flexible layouts and guidelines for snapped and fill views . these pages provide additional guidance on scaling your interface to fit and be useful in snapped view.
the on-screen keyboard is an integral part of windows 8 and there’s little doubt that external key devices (i.e. remote controls) will continue to grow in popularity as well. with that in mind, all windows 8 key events return a virtualkey enumeration rather than a literal keyboard scan code.
if your windows phone app somehow uses scan codes, either update it to use the new enumeration (best) or check the keyeventargs.keystatus.scancode property to see if the virtual key has a mapping to the original scan code.
for more information see plan for accessibility .
windows 8 is designed to be “touch first”, but it’s also designed to work exceptionally well with a mouse and stylus. to make supporting all three pointing ‘devices’ as easy as possible for developers, mouse-specific events were replaced with new unified pointer events like pointerentered and pointerpressed .
something else i found really interesting is that individual pointer events can be enabled and disabled per-element. on windows phone you can “hide” any element from all touch events by setting ishittestvisible=false . on windows 8 you can hide it from specific events by setting properties like isrighttapenabled .
for more information see responding to user interaction .
well, that’s it for the user interface article (whew!) be sure to bookmark the series and check back soon for more articles on porting windows phone apps to windows 8!
Published at DZone with permission of Jared Bienz, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.