Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Cross Platform Apps with Windows 8 & Windows Phone 8

1,331 views

Published on

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.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Cross Platform Apps with Windows 8 & Windows Phone 8

  1. 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. 2. What We Will Cover • MVVM • Solution Structure • Dealing with View Differences • Dealing with Code Differences • Navigation • Application Settings • Secondary Tiles
  3. 3. Introducing Charmed Framework
  4. 4. Charmed Framework • Open source, cross-platform MVVM support library – Windows 8 – Windows Phone 8 • https://github.com/brentedwards/Charmed
  5. 5. Charmed Reader [Demo]
  6. 6. MVVM Model-View-ViewModel
  7. 7. Model-View-ViewModel
  8. 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!
  9. 9. Solution Structure Laying the Foundation
  10. 10. Solution Structure • Windows 8 and Windows Phone 8 – Same Kernel – Compile Differently – Different Project Types
  11. 11. Solution Structure • My Approach: One Solution with Several Project Types
  12. 12. Solution Structure • Leverage “Add As Link” Feature
  13. 13. Dealing With View Differences
  14. 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. 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
  16. 16. Windows Phone Design Re-Use [Demo]
  17. 17. Dealing With Code Differences
  18. 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. 19. Dealing With Code Differences • How can I deal with platform differences? – 3 techniques • Compiler Directives • Abstraction • Compiler Directives + Abstraction
  20. 20. Compiler Directives • Usage – Windows 8 • #if NETFX_CORE – Windows Phone 8 • #if WINDOWS_PHONE • Pro – Easy • Con – Can be messy
  21. 21. Abstraction • Usage – Abstract platform-specific functionality into abstract class or interface • Pro – Clean • Con – Can be complex
  22. 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
  23. 23. Navigation
  24. 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
  25. 25. Navigation • Solution – Provide consistent interface which takes 1 parameter • Serialize that parameter to a string
  26. 26. Navigation [Demo]
  27. 27. Application Settings
  28. 28. Application Settings • Both platforms have very similar functionality – Different classes involved • Neither implementation can be easily mocked for unit testing
  29. 29. Application Settings • Solution – Provide consistent interface • Use compiler directives in implementation
  30. 30. Application Settings [Demo]
  31. 31. Secondary Tiles
  32. 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. 33. Secondary Tiles • Solution – Provide consistent interface with platform-specific implementations – Configure Windows Phone 8 to always launch through same page
  34. 34. Secondary Tiles [Demo]
  35. 35. What We Covered • MVVM • Solution Structure • Dealing with View Differences • Dealing with Code Differences • Navigation • Application Settings • Secondary Tiles
  36. 36. Questions?

×