Windows 8 and Windows Phone 8 now run on the same kernel. What does that mean for you, the developer? Two platforms, one codebase! With a little planning, much of your app code can be re-used between both platforms. In this session, we’ll take a look at useful patterns, tips, and tricks to get you writing one codebase that works across both Windows 8 and Windows Phone 8.
Boost PC performance: How more available memory can improve productivity
Cross Platform Apps with Windows 8 & Windows Phone 8
1. Cross-Platform Apps with
Windows 8 & Windows Phone 8
Brent Edwards
Associate Principal Consultant
BrentE@magenic.com
@brentledwards
brentedwards.net
https://github.com/brentedwards
2. What We Will Cover
• MVVM
• Solution Structure
• Dealing with View Differences
• Dealing with Code Differences
• Navigation
• Application Settings
• Secondary Tiles
8. Why is MVVM Cool?
• Separates Presentation from Functionality
• Promotes Testability
• Works great with Data Binding
• Easy collaboration with Designers
• Makes it easy to change out the View layer!
14. Dealing With View Differences
• What can be re-used across platforms?
– Presentation Logic Code (C#)
• What can’t be re-used across platforms?
– Presentation Code (XAML)
• Why?
– Different flavors of XAML
• Different styling concepts supported
– Different controls available
• GridView and ListView on Windows 8
• LongListSelector on Windows Phone 8
15. Dealing With View Differences
• What can be re-used from the presentation?
– Some design assets
• How is that possible?
– Windows 8 Snap View: 320px fixed width
• Why 320px?
– Mobile designers are used to it
• Windows Phone 8 Design -> Windows 8 Snap View
18. Dealing With Code Differences
• What is different?
– Navigation
• Same URI-based navigation scheme
• Accept parameters differently
– Application Settings
• Different classes
– Secondary Tiles
• Same concept, fundamentally different implementations
19. Dealing With Code Differences
• How can I deal with platform differences?
– 3 techniques
• Compiler Directives
• Abstraction
• Compiler Directives + Abstraction
20. Compiler Directives
• Usage
– Windows 8
• #if NETFX_CORE
– Windows Phone 8
• #if WINDOWS_PHONE
• Pro
– Easy
• Con
– Can be messy
21. Abstraction
• Usage
– Abstract platform-specific functionality into abstract class or interface
• Pro
– Clean
• Con
– Can be complex
22. Compiler Directives + Abstraction
• Usage
– Move compiler directives behind abstraction layer
• Pro
– Can keep the mess out of view models
• Con
– Still can be messy
24. Navigation
• Both platforms use URI-based navigation
– They differ in their use of parameters
• Windows 8 allows 1 parameter
– Can be anything
• Windows Phone 8 uses query string
– Can have many parameters, must all be strings
• Neither implementation can be easily mocked for unit testing
28. Application Settings
• Both platforms have very similar functionality
– Different classes involved
• Neither implementation can be easily mocked for unit testing
32. Secondary Tiles
• Both platforms have similar concept, but fundamentally different implementations
• Windows 8
– Requires user approval to pin/unpin tile
– Always launches through App.xaml.cs
– Asynchronous
• Windows Phone 8
– Doesn’t need user approval to pin/unpin tile
– Can launch directly into a specific page
– Synchronous
33. Secondary Tiles
• Solution
– Provide consistent interface with platform-specific implementations
– Configure Windows Phone 8 to always launch through same page