220 likes | 367 Views
Create cross-platform apps using Portable Class Libraries. Daniel Plaisted .NET Framework daplaist@microsoft.com @ dsplaisted 3-004. What we’ll learn. Share code across platforms with Portable Class Libraries Use the MVVM pattern to write cross-platform apps
E N D
Create cross-platform apps using Portable Class Libraries Daniel Plaisted .NET Framework daplaist@microsoft.com @dsplaisted 3-004
What we’ll learn • Share code across platforms with Portable Class Libraries • Use the MVVM pattern to write cross-platform apps • Put models and view models in portable libraries • Create platform-specific views • Create portable abstractions for non-portable functionality • Implement the abstractions for each platform you target • Consider using a service locator or IoC container to hook up implementations • How to create cross-platform apps that take full advantage of platform-specific features while maximizing code reuse for the rest of your app
Portable Class Libraries • One source • One project • One binary • Multiple platforms!
Portable platform/feature matrix What can I use and where?
Demo • Disentanglement • github.com/dsplaisted/disentanglement
Model-View-ViewModel(MVVM) Views How to display information Written in XAML View Models What information to display Flow of interaction Models Data objects Business logic Etc. View Platform-specific Databinds View Model References Portable Model
Cross-platform app architecture Windows Store App Windows Phone App Startup Startup Views Views Platform specific functionality Platform specific functionality Portable Class Library View Models Reference Reference Models Platform functionality abstractions
Demo • Creating a simple cross-platform app
Hooking platform-specifics to portable code • Pass dependencies in from app code • Service locator/platform abstraction • IoC container
Simple service locator • publicclassServiceLocator • { • publicstaticIFileStorageFileStorage { get; set; } • publicstaticIPhotoChooserPhotoChooser { get; set; } • }
What we’re learning • Share code across platforms with Portable Class Libraries • Use the MVVM pattern to write cross-platform apps • Put models and view models in portable libraries • Create platform-specific views • Create portable abstractions for non-portable functionality • Implement the abstractions for each platform you target • Consider using a service locator or IoC container to hook up implementations • How to create cross-platform apps that take full advantage of platform-specific features while maximizing code reuse for the rest of your app
Contoso Helpdesk • Demo
More patterns for portable apps • Navigation • IoC • Async • Azure Service Bus
Azure service bus MSDN Magazine: Create a Continuous Client Using Portable Class Libraries
Cross-platform apps Android iOS Windows Windows Phone Xamarin Cloud for mono for Android
Demo • Twitter Search
In review: what we learned • Share code across platforms with Portable Class Libraries • Use the MVVM pattern to write cross-platform apps • Put models and view models in portable libraries • Create platform-specific views • Create portable abstractions for non-portable functionality • Implement the abstractions for each platform you target • Consider using a service locator or IoC container to hook up implementations • How to create cross-platform apps that take full advantage of platform-specific features while maximizing code reuse for the rest of your app
Related Sessions • How to Leverage your Code across WP8 and Windows 8 – 3-043 • Designing awesome XAML apps in Visual Studio and Blend for Windows 8 and Windows Phone 8 – 3-006 • The Evolution of .NET – 3-016 • Deep Dive into the Kernel of .NET on Windows Phone 8 – 3-005
Additional Resources • http://tinyurl.com/Build2012PCL • Please submit session evals on the Build Windows 8 App or at http://aka.ms/BuildSessions