04 |Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio Ben Riga

Slides:



Advertisements
Similar presentations
Module 1: Creating an Application by Using Windows Presentation Foundation Overview of WPF Creating a Simple WPF Application Handling Events and Commands.
Advertisements

Lessons learned from developing a Windows 8 Metro application in C# Frode Nilsen Nilsen Labs Ticki.
CROSS PLATFORM DEVELOPMENT WITH MVVM CROSS By Ken Tucker.
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Advanced Object-Oriented Programming Features
Real world Windows Phone development Igor
Building Silverlight Applications Using the MVVM pattern An Introduction by Peter Messenger Senior Developer – Qmastor
Writing Universal Apps for Windows and Windows Phone GREG STOLL 10/18/2014.
Joe xamlcoder.com/blog Silverlight / WPF Consultant.
© 2014 HL7 ® International. Licensed under Creative Commons. HL7 & Health Level Seven are registered trademarks of Health Level Seven International. Reg.
Agenda Unit Test Framework for the XAML app developer Automated end-user testing using Coded UI Test Q&A.
Introducing Xamarin 2.0 Introducing Xamarin 2.0 Michael Hutchinson
OOP Languages: Java vs C++
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
Hot Tuna CROSS PLATFORM DEVELOPMENT WITH.NET, XAMARIN AND MVVMCROSS.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Best Design Practices Using the Qt Runtime SDK (using QML)
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
An Introduction to Silverlight Matt Harrington Developer Evangelist, Microsoft October 20, 2011.
Visual Programming Fall 2012 – FUUAST Topic: Development environment.
Windows Phone 8 Tips & Tricks for Developers Sascha Corti, Microsoft Switzerland Technical Evangelist | techpreacher.corti.com.
Mid-term Presentation Validation of Architecture Rules & Design Patterns 25 th May Shravan Shetty &Vinod J Menezes Supervised by, Prof. Dr. M. v. d. Brand.
Understanding Xamarin Development Matt
CSSE501 Object-Oriented Development. Chapter 4: Classes and Methods  Chapters 4 and 5 present two sides of OOP: Chapter 4 discusses the static, compile.
Distribution and components. 2 What is the problem? Enterprise computing is Large scale & complex: It supports large scale and complex organisations Spanning.
Lecture 12 March 16, The Scope of a Variable What if there are two variables with the same name? –A local or block-local variable can have the same.
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
Quick overview of ASP.NET Ajax Ajax deep-dive Cover some key real-world problems Discuss solutions, patterns, opportunities Lots of demos And more of.
Windows 8 for Existing.NET Developers Tim Heuer Program Manager Windows Developer Experience Microsoft Corporation.
Windows 10 UWP MVVM In Depth
Module 4 Taking Control of the User Interface. Module Overview Sharing Logical Resources in an Application Creating Consistent User Interfaces by Using.
JAVA INTRODUCTION. What is Java? 1. Java is a Pure Object – Oriented language 2. Java is developing by existing languages like C and C++. How Java Differs.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Advanced Object-oriented Design Patterns Creational Design Patterns.
Friday, March 8 Creating real Custom Controls Kelvin van Geene 12:15.
Platform abstractionSeparate UI and logic.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
OpenMRS Create New Module.
Design Patterns. Outline Purpose Purpose Useful Definitions Useful Definitions Pattern Overview Pattern Overview.
Model View ViewModel Architecture. MVVM Architecture components.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Perfecto Mobile Automation
05 | Xamarin Forms, kódosztási technikák Farkas Bálint | Technical Evangelist | Microsoft.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
Programming with MVVM Miguel A. Castro Architect -
Vladimir Milev New Venture Software Sharing Code between WPF and Universal Apps.
/DEV/TM #1 Building Cross-Platform Apps with Xamarin and MvvmCross Flavius-Radu DEMIAN.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
The cutting edge event for ITPros and Devs December 7-8, 2013 Athens, Greece Fix it once use it everywhere Elias Markelis MCT, Windows Phone Enthusiast.
Data Binding, Binding Properties Doncho Minkov Telerik School Academy Technical Trainer
State of the Art in Mobile Development - AndRES Käver, 2016
Real world Windows Phone development
INF230 Basics in C# Programming
Unit testing your metro style apps built using XAML
Ch 10- Advanced Object-Oriented Programming Features
Ben Riga 02 | Basics of View Models Ben Riga
By SmartBoard team Adapter pattern.
Customizing your device experience with assigned access
Module 1: Getting Started
MIX 09 12/8/2018 4:33 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Social Media And Global Computing Creating DLLs with Visual Studio
What’s new for Windows 8 Devs Part 2
Build /23/2019 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Microsoft Office 4/3/2019 Deep Dive into native Universal App development with the Office 365 APIs Speaker name Title Microsoft Corporation © 2012 Microsoft.
XAML Deep Dive for Windows & Windows Phone Apps Jump Start
Hans Zaunere, Managing Member
Bringing existing managed code into Metro style apps
An Introduction to the Model-View-ViewModel Pattern
Presentation transcript:

04 |Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio Ben Riga

Building Apps for Both Windows 8 and Windows Phone 8 Jump Start 01 | Comparing Windows 8 and Windows Phone 8 02 | Basics of View Models 03 | MVVM ( (Model-View-ViewModel) 04 | Sharing Code Course Topics

Sharing Code Between Windows Phone 8 and Windows 8 in Visual Studio

Reuse techniques Portable library Shared source code Inheritance Conditional compilation Partial classes and methods Q&A Agenda

Reuse Techniques

Portable Class Library project template in Visual Studio 2012 (except Express) C# or Visual Basic Good for creating a cross-platform.dll with pure business logic Only managed code Single codebase for Windows, Silverlight, Windows Phone, or Xbox Only shared assemblies are available for use (mostly restricted to System namespaces) Overall, limited, but provides portable, modular, and encapsulated code Portable Library

Demo 1: Portable Class Library

Share code files between multiple projects A single change shows up in all projects Use Add As Link to include an external code file in multiple projects When the APIs don’t match, use another technique to separate platform-specific code, such as: inheritance, #if conditional blocks, or partial classes and methods. Shared Source Code

Enable/disable pieces of code based on target platform (or any other compiler variable) Platform-specific compilation constants: NETFX_COREWindows 8 WINDOWS_PHONEWindows Phone 8 Useful for when there are subtle differences in the APIs If overused, code can become unreadable and hard to maintain #if Conditional Blocks

#if Conditional Block Examples (1/2) #if NETFX_CORE using Windows.UI.Xaml.Media.Imaging; #else using System.Windows.Media.Imaging; #endif

#if Conditional Block Examples (2/2) public object Convert(object value, Type targetType, object parameter, #if !NETFX_CORE CultureInfo culture #else string language #endif )

Demo 2: #if Conditional Blocks

Put shared functionality in base class and platform-specific code in sub-classes Separates cross-platform features from platform-specific features Base class can be abstract to enforce platform-specific implementations Two main approaches: The base class contains fully implemented logic. The sub-classes provide additional platform-specific functionality. The base class is incomplete. Subclasses implement the abstract methods to provide platform-specific functionality. Inheritance

/// /// Base View Model used across both platforms /// public class AlbumPageViewModel : NotifyBase, IViewModel {... } /// /// Sub-class containing additional information used in the Windows application /// public class WinAlbumPageViewModel : PhotoCollectionViewModel, ISupportsDesignTimeDataViaCode { } Inheritance Examples (1/2)

/// /// Abstract base class available across both platforms /// public abstract class StartPageViewModel : NotifyBase,IViewModel { protected abstract bool NavigatedToPhoto(); } /// /// Sub-class implementing the abstract method /// public class WinStartPageViewModel : StartPageViewModel, ISupportsDesignTimeDataViaCode { protected override bool NavigatedToPhoto() { NavigationService.Navigate (SelectedPicture.Path); return true; } Inheritance Examples (2/2)

Demo 3: Inheritance

Shared functionality in one code file Ex: DataModel.cs Platform-specific code in another code file Ex: DataModel.WP8.cs Partial class definitions compiled into a single class Partial Classes

Can use partial methods as a mechanism to separate out platform-specific logic Two parts: the definition and the implementation Both parts must be in the same partial class If no implementation exists, the compiler removes all calls to the method Partial Methods

Partial Classes Example /// /// DataModel.cs /// public partial class DataModel:IDataModel { public async Task > GetFoldersAsync(IFolder root) { //... var folders = await LoadFolders(root); //... return folders } /// /// DataModel.WP8.cs /// public partial class DataModel { private async Task > LoadFoldersAsync(IFolder root) { //... }

Demo 4: Partial Classes

Recap

Develop apps for both Windows Phone 8 and Windows 8! Even if you do not initially target both platforms, it does not hurt to plan for the future. Be aware of which APIs are common to both platforms and which are not. Use DataBinding to make your life easier when creating complex UIs that need to be dynamically updated with data. Use commands to execute a piece of code when a button is clicked MVVM works well with data binding Takeaways

Consider designing your apps around the MVVM pattern. Even if you do not use MVVM, separate the data model from the UI. This lets you reuse the data model in the future. Use strategies so that you can reuse source code Portable libraries Shared source files #if conditional blocks Inheritance Partial classes, partial methods Takeaways

Windows 8, Windows Phone 8 APIs Windows Phone API QuickStart Data Binding Data Binding Overview XAML Data binding sample MVVM “Using the MVVM Pattern in Windows” “MVVM Light Toolkit” Additional Resources Sharing Code Windows Phone 8 and Windows 8 app development Sample Code “Windows 8 app samples” “Windows Phone samples” All resources available at:

Q&A

Thank you!