Don´t do more "copy and paste" between
Windows Store and Windows Phone Apps
Sara Silva
http://netponto.org35th Meeting in ...
Sara Silva
Windows 8 & Windows Phone Developer
Communities :
 MCPD: Windows Developer 3.5
 MCTS: WPF 3.5/4.0 and Windows...
Agenda
• Introdution
• Sharing code files
• Portable Class Library
• Portable Class Library + MVVM
• Libraries
• Conclusion
Introdution
2 Platforms
3 applications
6 projects
Pílula WP Pílula Win8
Galinho WP Galinho Win8
24 WP 24 Win8
Nota: Same v...
Introdution
• Repeated code between projects => 2 times the same task.
• Bug in WP => bug in Win8 and vice versa => 2 time...
Share code files
• Use “Add as Link” to include same files in multiple projects.
• Use directives for platform specificati...
Share code files
#if !NETFX_CORE
public object Convert(object value, Type targetType, object parameter, CultureInfo cultur...
Share code files
Partial Classes and partial methods
• Shared functionality in one code file.
• Platform specific code in ...
Share code files
Example, MVVM Light toolkit :
“Add as Link”
Portable Class Library
More help for developing cross-platform applications using. Net
Framework, since it allows you to c...
Portable Class Library
Features supported on various platforms *:
* .Net Framework greater or equal to 4.0.3
Portable Class Library
The documentation on MSDN announces support:
Portable Class Library
When create a project
Visual Studio 2010 (Extention +SP1) and 2012 provides a Portable Class Librar...
Portable Class Library
Visual Studio 2010 (Extenstion +SP1) and 2012 provides a Portable Class Library project template.
R...
Portable Class Library Project
Portable Class Library
• Not contains types related to UI because the UI behavior differs between the
different platforms;...
Portable Class Library + MVVM
Portable Class Library + MVVM
Available classes to help MVVM implementation:
System.Collections.ObjectModel
• ObservableCo...
Consuming Odata Service
Architecture
*only external portable libraries
Libraries
• Microsoft.Bcl.Async
Allow to use async/await without .Net Framework 4.5
• Portable Toolkit for MVVM
Fork from ...
Conclusion
• Separate UI from app logic using the Model-View-ViewModel pattern.
• Share portable .NET code in Portable Cla...
Q & A
References
• Cross-Platform Development with the .NET Framework
• Using Portable Class Library with Model-View-View Model
...
Others Samples
• PortableNotepad - This sample shows how to access non-portable functionality from portable code by creati...
Sponsors “GOLD”
Twitter: @PTMicrosoft http://www.microsoft.com/portugal
Sponsors “Silver”
Sponsors “Bronze”
Upcoming meetings
• 23/02/2013 – February (Lisbon)
16/03/2013 – March (Lisbon)
Reserve these days! :)
Thanks!
Sara Silva
geral@saramgsilva.com
http://www.saramgsilva.com
http://twitter.com/saramgsilva
http://pt.linkedin.com/...
Upcoming SlideShare
Loading in …5
×

Do not do more copy and paste between windows store and windows phone apps

4,974 views
4,828 views

Published on

See more information in pcl.codeplex.com

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,974
On SlideShare
0
From Embeds
0
Number of Embeds
2,450
Actions
Shares
0
Downloads
29
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • MVVM Light Source Code:

    Open Win8 and WP8 Solution ;

    Show Code
    How to do “Add as Link” – use the RelayCommand – file is inside the .Net3,5
    Show directives - RelayCommand
    Parcial class in diferent files. Show the WeakFunc.Win8


  • Creating a empty PCL project
    Show the dialog for choose the targets
    Edit the targets
    Show the subset
  • What’s the MVVM

  • Be Pragmatic:
    Develop UX specific to the target platform
    Don’t attempt to share UX resources (styles, controls, pages etc)
    Reuse and share code between platforms
  • Do not do more copy and paste between windows store and windows phone apps

    1. 1. Don´t do more "copy and paste" between Windows Store and Windows Phone Apps Sara Silva http://netponto.org35th Meeting in Lisbon - 26/01/2013
    2. 2. Sara Silva Windows 8 & Windows Phone Developer Communities :  MCPD: Windows Developer 3.5  MCTS: WPF 3.5/4.0 and Windows Forms 3.5  Math Degree: Specialization in Computing - DMUC
    3. 3. Agenda • Introdution • Sharing code files • Portable Class Library • Portable Class Library + MVVM • Libraries • Conclusion
    4. 4. Introdution 2 Platforms 3 applications 6 projects Pílula WP Pílula Win8 Galinho WP Galinho Win8 24 WP 24 Win8 Nota: Same version for WP7.5 and WP8
    5. 5. Introdution • Repeated code between projects => 2 times the same task. • Bug in WP => bug in Win8 and vice versa => 2 times the same correction. • Less features. • Less time for others taks. • Cost are double: “If the cost for the company is Y €/hour => 2*Y€/hour” “If the cost is sleep time => Less time sleeping ” • Demotivation for developers.
    6. 6. Share code files • Use “Add as Link” to include same files in multiple projects. • Use directives for platform specifications. • Use partial class and partial methods. • Change once, change everywhere. “Reusing code by including code files in multiple projects.”
    7. 7. Share code files #if !NETFX_CORE public object Convert(object value, Type targetType, object parameter, CultureInfo culture) #else public object Convert(object value, Type targetType, object parameter, string culture) #endif Using directives: • NETFX_CORE Windows 8 • WINDOWS_PHONE Windows Phone It can “generate” code unreadable
    8. 8. Share code files Partial Classes and partial methods • Shared functionality in one code file. • Platform specific code in additional code file. • Classes are marked as partial and compiled into a single class. • Separates platform specific features. • Can use partial methods as a mechanism to separate out platform specific logic. DataSource.cs | DataSource.WP8.cs | DataSource.Win8.cs
    9. 9. Share code files Example, MVVM Light toolkit :
    10. 10. “Add as Link”
    11. 11. Portable Class Library More help for developing cross-platform applications using. Net Framework, since it allows you to create "portable assemblies" that can be referenced in projects for multiple platforms without the need to make changes. Will contain the lowest common denominator types: • .NET Framework • Silverlight • .NET for Windows Store apps, • Windows Phone • Xbox 360
    12. 12. Portable Class Library Features supported on various platforms *: * .Net Framework greater or equal to 4.0.3
    13. 13. Portable Class Library The documentation on MSDN announces support:
    14. 14. Portable Class Library When create a project Visual Studio 2010 (Extention +SP1) and 2012 provides a Portable Class Library project template. “targets” definitions: Editing the target in a project
    15. 15. Portable Class Library Visual Studio 2010 (Extenstion +SP1) and 2012 provides a Portable Class Library project template. Result: “ One Source One Project One Binary Multiple Platforms!”
    16. 16. Portable Class Library Project
    17. 17. Portable Class Library • Not contains types related to UI because the UI behavior differs between the different platforms; • Windows 8 is required for create Windows Store Apps, but is not required for create Portable Class Libraries that supports Windows Store Apps. • Silverlight-based application must ensure that the minimum runtime version required for the application is set to version 4.0.60129.0 or later <param name="minRuntimeVersion" value="4.0.60129.0" />
    18. 18. Portable Class Library + MVVM
    19. 19. Portable Class Library + MVVM Available classes to help MVVM implementation: System.Collections.ObjectModel • ObservableCollection<T> class • ReadOnlyObservableCollection<T> class System.Collections.Specialized • INotifyCollectionChanged class • NotifyCollectionChangedAction class • NotifyCollectionChangedEventArgs class • NotifyCollectionChangedEventHandler class System.ComponentModel • DataErrorsChangedEventArgs class • INotifyDataErrorInfo class • INotifyPropertyChanged class • System.Windows.Input.ICommand class • All classes in the System.ComponentModel.DataAnnotations namespace
    20. 20. Consuming Odata Service
    21. 21. Architecture *only external portable libraries
    22. 22. Libraries • Microsoft.Bcl.Async Allow to use async/await without .Net Framework 4.5 • Portable Toolkit for MVVM Fork from toolkit MVVM Light: Portable.MvvmLightLibs • MvvmCross Library for MVVM in Windows Phone, Windows Store, iOS, and Android • Portable Class Libraries Contrib Portable adapters and APIs • Json.NET JSON framework
    23. 23. Conclusion • Separate UI from app logic using the Model-View-ViewModel pattern. • Share portable .NET code in Portable Class Library • “Abstactration pattern is the key” • Dependency injection allow to encapsulate platform specifications. • Use common Windows Runtime API (Add as Link) • If necessary, extend shared classes to add specific functionality of the platform. • When we want to share code, designing the architecture should bear this in mind!
    24. 24. Q & A
    25. 25. References • Cross-Platform Development with the .NET Framework • Using Portable Class Library with Model-View-View Model • Create Cross-platform Apps using Portable Class Libraries • Building Apps for Windows Phone 8 Jump Start (MVA) • Visual Studio Toolbox:Portable Class Libraries • Create a Continuous Client Using Portable Class Libraries • How to Leverage your Code across WP8 and Windows 8 • Portable Library Articles series by Jeremy Likness • How to Make Portable Class Libraries Work for You • Portable Class Library Enlightenment / Adaptation • Portable Class Libraries – Net Framework 4.0 • Portable Class Libraries – Net Framework 4.5
    26. 26. Others Samples • PortableNotepad - This sample shows how to access non-portable functionality from portable code by creating a portable abstraction with platform-specific implementations. Goals: Abstraction for Load / Save data in files Projects: Windows Phone, Windows Store App, WPF App • ContosoHelpdesk – This demo show advanced concepts. Goals: Navigation, inversion of control, and synchronizing data across multiple clients with Windows Azure Service Bus. Projects: Windows Phone, Windows Store App Note: Use Autofac portable library (IoC Container) • TwitterSearch – This sample shows how to create a twitter search client. Goals: Twitter Search API, Azure Mobile Services, Projects: Windows Phone, Windows Store App, Console App Note: Use MVVMCross portable library • Disentanglement - This is a solver for Thinkfun's Gordian's Knot puzzle which runs on Windows and Windows Phone. It uses a Portable Class Library to share the solver code between the different platforms Goals: Share the solver code. Projects: Windows Phone App, Desktop App, Xbox App • PixPresenter - is a photo sharing app that enables you to connect to another device using Proximity (NFC) and a tap gesture, and then send pictures back and forth between the connected devices. It demonstrates code sharing techniques that you can use when developing an app for bot Goals: Windows Runtime API common code Projects: Windows Phone, Windows Store App (C# and C++)
    27. 27. Sponsors “GOLD” Twitter: @PTMicrosoft http://www.microsoft.com/portugal
    28. 28. Sponsors “Silver”
    29. 29. Sponsors “Bronze”
    30. 30. Upcoming meetings • 23/02/2013 – February (Lisbon) 16/03/2013 – March (Lisbon) Reserve these days! :)
    31. 31. Thanks! Sara Silva geral@saramgsilva.com http://www.saramgsilva.com http://twitter.com/saramgsilva http://pt.linkedin.com/in/saramgsilva http://www.facebook.com/saramgsilva

    ×