Build for both: Windows and Windows PhoneMatt HidingerClarity Consulting 2-215
Clarity ConsultingWindows Phone Dev MVP
So umm… you’re not with Microsoft?
But first… a phone!
Design for bothDevelop for bothArchitecture & patterns
Sharing
Image credit: Jason Emprey
Real-world stocks
Design for both
Same design language
What do they have in common?
C#.NETXAMLWinRT
Windows PhoneWindows
Windows Phone800x4801280x7681280x1024
How do they differ?
Form factors, mostly
Windows1024x768…to…3200x1800+
Landing pages
GridViewGrouped by sectionHorizontal scrolling
PanoramaItem per sectionHorizontal and vertical scrolling
Panorama
Lists of data
Vertical scrollingOptionally grouped
Jump list to quickly navigate
GridView LongListSelectorHorizontal scrolling
Optionally groupedSemantic zoom to quickly navigate
App bars
AppBar ApplicationBarTop and Bottom
Supports circular buttonsAnd/or any content you want
Bottom onlySupports circular buttons
And/or menu items
Back buttons
On screen On device
My personal favorite
Design is more than the appearanceTune the experience and use cases for the form factorPay attention to the details, modern design isn’t lack of design
Inspiration is everywhere
Develop for both
Sharing an assembly
One SourceOne ProjectOne Binary
Multiple Platforms!
Portable Class Libraries
Portable Class Library
Demo
Sharing source code
CtrlCtrl
-C-V
When? XAML
Image credit: http://quickmeme.com
Linked files
Linked files
Hold Alt and drag a folder to link multiple files at once!
Windows Phone
Windows
Linked Files
Demo
#if NETFX_COREDispatcher.RunAsync(CoreDispatcherPriority.Normal, myAction);#endif
Compiler directives
#if WINDOWS_PHONEDeployment.Current.Dispatcher.BeginInvoke(myAction);#endif
Windows
Windows phone
Compiler Directives
Demo
ComparisonSharing an assembly (PCL)Code remains clean and single purposeBuild, test, compile onceLimited API accessCan’t reference non-PCL assembliesWon’t work with Express SKUs
Sharing source code (linked files)
Full API access on the platform compiling itCan tweak source per platform using #if
Code can become complex due to compiler directivesMinor Visual Studio quirks: “This document is already open”
TL;DR: use them both
You know C#You know .NETYou know and love XAML (right?)
Use your skills, Luke
Architecture & patterns
Portable Class Library
CoreViewModels
Services
Models
WindowsApp Startup / Lifecycle
ViewsControls
ConvertersViewModels
Windows PhoneApp Startup / Lifecycle
ViewsControls
ConvertersViewModels
Linked
Building real-world stocks
Demo
Summary
What to share?Linked sourceü Convertersü Commands✋ Controls (if it makes sense)✋ View Models (if it makes sense)
User Interfaceü Static assetsü Design language XAML: Not right now
PCLü Modelsü Business logicü Web Servicesü Helpersü Logging✋ View Models (if it makes sense)✋ Commands (if it makes sense)
Architect with sharing in mindPut as much into a PCL as possibleUse a platform adapter to Do More in CoreUse #if conditions for minor code differencesExtension methods can bridge missing APIsMaximize the user experience for each platform
Mix and match techniques
Image credit: Daniel E Lee
PortableHttpClientPCLStorageMetroLog
Beneficial frameworks
MVVMCaliburn.MicroMVVM Light
Try it yourself!
Download the full source for this talk in a few days
http://bit.ly/BuildRealWorldStocks
Related sessionsStory of Nokia Music, from Windows Phone to Windows Store2-219 – Matthew Cooper – North 134 – 30 minutes from now!
Windows Phone Development Best Practices2-216 – Stefan Wick – North 134 – Friday @ 10:30 AM
MVVM In Action – Hulu Case Study2-205 – Matthias Shapiro – North 134 – Friday @ 12:00 PM
References1. Daniel Plaisted
- Making Portable Libraries Work For You2. Matthias Shapiro – TechEd 2013,
Build It Once For Both3. Rajen Kishna's Technical Tidbits4. Doug Holland - Sharing Code, MSDN Magazine5. @dotMorten – Code Sharing Wizard
Join other speakers and Microsoft employees to talk about sharing
Today @ 6 PMMicrosoft Office835 Market Street, Suite 700
Sharing code meet-up!
Drinks and appetizers provided
@MattHidinger
Thank you!Q&A
Evaluate this session
Scan this QR code to evaluate this session and be automatically entered in a drawing to win a prize!
© 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.