Windows Phone 7 Developer Tips and Tricks
| CommentsOn the heels of the Windows Phone Developer Tools and Silverlight for Windows Phone Toolkit releases I saw a lot of exhaling going on in the hallways today. Apparently Jeff saved his largest one for an avalanche of knowledge on Twitter in the late afternoon. Jeff Wilcox is a developer on the Silverlight team and has been working on the Silverlight for Windows Phone initiative as well as the toolkit released today. He was headed out on vacation but decided to throw out some words of wisdom for Windows Phone developers working in Silverlight. Here’s some of those nuggets – I wanted to capture them before he left because who knows how long they’ll stay in Twitter. It reads like a true guide to developing great apps on Windows Phone…
- Panorama looks nice, but Pivot will offer faster start time.
- You can also set a Background image to a Pivot. You won't get the parallax effect, but it is another option.
- Be aware of how many pano and pivot items you do have. Memory expands quick when you have a lot of views and images!
- Even if you have a 30k compressed JPEG image, at runtime that becomes an uncompressed surface that may take several MBs of memory
- Pivot and Panorama can have UI element headers and titles, too, but you'll need to apply your own styling (fonts and sizes)
- Beware that UI elements larger than 2000x2000 pixels that are bitmap cached clip on Windows Phone 7. We know it isn't perfect, but beware k?
- Setting SelectedIndex before the items are set on a Pivot causes an exception. Wrap in a try/catch or wait for loaded (sorry!)
- A slideshow app in 5 minutes: Pivot with null Header and Title and item headers. Beware memory use though.
- A lot of people try building 'wizard' screens with panorama & pivot control. Please don't do this! Thx, the "UX gods"
- Layout is a killer. But like death, you eventually have to pay it for everything.
- So consider delay loading controls and screens. A Panorama with a billion items will take forever to load due to layout.
- If you're not using PerformanceProgressBar, I'll send @JustinAngel after you ProgressBar for Windows Phone 7
- If your app rocks and starts really quick *on a device* consider not using a splash screen
- It's true. Your 6-core machine running the wp7 emulator is NOT indicative of device (single core!) performance. Beware!
- We've talked perf before... Content over Resources for images means fast startup time http://bit.ly/9DhVbd
- If you're using Panorama, a Resource background will load immediately compared to Content
- Remember that for ingestion to the marketplace, your apps need to consume under 90MB of memory
- However on devices with > 256MB, its cool to use more *in those cases
- long deviceTotalMemory = (long)DeviceExtendedProperties.GetValue("DeviceTotalMemory");
- long applicationCurrentMemoryUsage = (long)DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage");
- long applicationPeakMemoryUsage = (long)DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage")
- Your compositor thread should rock out around 60fps all the time please. #wp7dev perf counters: http://bit.ly/busJIi
- If your UI thread gets pegged, your compositor thread will suffer... remember your BackgroundWorker kids!
- Unfortunately the "Analytics" type from desktop Silverlight is not on the phone today, so you can't measure CPU in a regular app
- Having a single DispatcherTimer in your app can affect your battery life regardless of interval. Chose wisely
- You can set the Foreground property on Pivot to set the title and header text color
- Using a map control inside a Panorama or Pivot is not recommended for a number of UX and technical reasons. Navigate to a subpage.
- Please use text styles and never hardcode sizes or default fonts.
- The panorama/pivot items expect most their contents to have a 12px margin left/right for UX reasons. The default styles have this.
- So if you have something in a pano/pivot item with 0 margin & padding, your UX will be funky
- Fill rate is super important. Keep it under 2.5 please
- What is fill rate? 1.00 means one screen of pixels being rendered every frame.
- Check your apps for extra, un-needed background colors on pages, controls, etc.. They impact perf.
- That sexy "tilt" effect? Use Peter's behavior http://bit.ly/90Z1yR and/or check out the MSDN docs
- DataTemplates with a bunch of StackPanels and Grids? Try to simplify to a Grid with the right col/rows instead for perf wins.
- Unit testing in a quick and dirty way is possible on the Windows Phone thx to the sl unit test fx. http://bit.ly/a0DWah
- Only use Dispatcher.BeginInvoke when you must. Look at SmartDispatcher (ps old code sry) http://bit.ly/axHh36
- For a "wide" Panorama item, set the item's Orientation to "Horizontal"
- Play with the cache and redraw vis. settings to see what's being cached in your app http://bit.ly/busJIi
- Things in a list/scroll viewer are often automatically bitmap cached by Silverlight for Windows Phone runtime
- If you have a progress bar with IsIndeterminate="True" in your app, even if its hidden those storyboards are costly! Set to False!
- We did work on Windows Phone 7 to move more networking to the background thread - hope it helps
- When a Panorama loads, all its items go through a render pass. For pivot, it is done incrementally for neighboring items.
- When making web requests, see if the service lets you scope down the fields that are returned for quicker perf (and JSON over XML!)
- If you navigate to a subpage, the old page will stick around - so complex pano/pivot pgs stay in memory unless you're proactive
- The "app deployment tool" installed with the dev tools lets you run others apps in emulator/device without needing source
- We optimize for loading some things from isolated storage. Images from an isostore stream may load faster than a MemoryStream
- If your source files have "Black" or "White", you might be doing it wrong. PhoneForegroundBrush, PhoneBackgroundBrush instead!
- If your control's dep. property has a change handler, animating that prop. will always happen on the UI thread (no gpu accel.)
- Animating Opacity on a CacheMode="BitmapCache" element = compositor thread (GPU!)
- In the RTM tools, scroll viewers all have the "bounce" effect automatically
- If you ignore the phone's theme (and go all light bg, like the mail app), your scrollbarsmust be retemplated or you won't see them!
- Although data binding is not evil, an observable col. with a complex data temp. and 200k items is evil.
- The web browser control won't let you NavigateToString until it has loaded.
- If you have an app with a lot of different web browser controls, think about consolidating to one, so it only has to load once.
- Panorama is designed to be a starting place. Think whitespace. Not tons of data
- Free performance win: when you use Panorama the way the UX guidelines recommend, it is faster! http://bit.ly/9zTxtU
- Those theme xamls for #wp7? Yeah they are in %ProgramFiles%\Microsoft SDKs\Windows Phone\v7.0\Design\
- Resist the urge to Panorama every app. It is a sweet UX thing when used right…but not just because.
- Resist the urge to iPhone gradient your apps. Think outside the box! Also it avoids color banding...
So as you can see, he sort of knows what he’s talking about :-). Go subscribe to his blog and follow him on Twitter. Other helpful links:
- Jeff on Hanselminutes talking about Windows Phone 7 application performance
- Creating High Performance Silverlight for Windows Phone Applications (whitepaper)
- Shane Guillet on optimizing Windows Phone Silverlight Applications (video)
Thanks Jeff for sharing your awesomeness!
Hope this helps!
Please enjoy some of these other recent posts...
Comments