05 Xamarin Forms kdosztsi technikk Farkas Blint Technical
05 | Xamarin Forms, kódosztási technikák Farkas Bálint | Technical Evangelist | Microsoft
Module Overview • Xamarin. Forms bevezetés – Mi ez? – Követelmények • Xamarin. Forms vezérlőelemek • Kódosztási technikák – Portable Class Library-k – MVVM – Dependency Injection • Heritage Properties Xamarin. Forms alapokon • Xamarin. Forms Custom Renderer-ek
Xamarin. Forms bevezetés
What is Xamarin. Forms?
What is Xamarin. Forms?
Portable Class Library
Xamarin. Forms
C# Platform Specific Portable Class Library or Shared Project Shared C# Interface Code (Xamarin. Forms) Shared C# App Logic (View. Models, Models etc) C# Platform Specific
Requires • i. OS 6. 1+ Requires • Android 4. 0+ Requires • WP 8. 0+ (Silverlight) • Win. RT previewben
Xamarin. Forms vezérlőelemek
Xamarin. Forms 1. 2. 3. 4. Pages Layouts Views Cells
Xamarin. Forms - Pages UIView. Controller Activity Page
Xamarin. Forms - Layouts
Xamarin. Forms - Views
Xamarin. Forms - Cells
Xamarin. Forms Data. Binding Engine
DEMO Intro to Xamarin. Forms
Code Sharing – Portable Class Libraries
Portable Class Libraries Portable Class Library project template in Visual Studio 2012/2013 (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) Limited, but provides portable, modular, and encapsulated code
Portable Class Library One Source One Project One Binary Multiple Platforms
Portable Class Libraries Limits Platform Specific OS Functions • Storage (no file I/O access) • Alerts • Message. Box • GPS
Shared Projects #ifdef parancsokkal targetált kód Build időben hozzámásolódik a szülőprojekthez és azzal együtt fordul (ellentétben a PCL-lel, ami önálló DLL, így nem tudja, honnan van bereferálva)
Code Sharing – MVVM, Inversion of Control (Io. C) and Dependency Injection
Dependency Injection Container Locator Type 1 : IType 1 Register Concrete Type 2 : IType 2 PCL Register View. Model IType 2
Using Dependency Injection namespace Heritage. Properties. PCL { public interface IGps. Service { Task<Location> Get. Location(); } }
public partial class Location. Service : IGps. Service { CLLocation. Manager manager = new CLLocation. Manager(); public Task<Location> Get. Location() { manager. Start. Updating. Location(); return Task. Run(() => { var ret = new Location(); // code omitted for space // return the location return ret; }); } }
Simple. Ioc. Default. Register<IGps. Service, Location. Service>(); Simple. Ioc. Default. Register<Main. View. Model>(); public Main. View. Model(IGps. Service gps) { this. Gps. Service = gps; }
Service. Locator. Current. Get. Instance<Main. View. Model>();
DEMO Implementing Heritage Properties for Android, i. OS and Windows using Xamarin. Forms
Maps & Custom Renderers
Xamarin. Forms – Custom Renderers // register the i. Gps. Service for i. OS Simple. Ioc. Default. Register<IGps. Service, Location. Service>(); public Main. View. Model(IGps. Service gps, Heritage. Property. Service service, INavigation navigation) { }
Xamarin. Forms – Custom Renderers [assembly: Export. Renderer(typeof(Map. Renderer 2), typeof(Map. Renderer 2 Android))] public class Map. Renderer 2 : Map { } map = new Map. Renderer 2() { Is. Showing. User = true, Height. Request = 100, Width. Request = 960, Vertical. Options = Layout. Options. Fill. And. Expand };
Xamarin. Forms – Messaging Custom Renderer Send Message To Invoke Method Send Message To Notify of Event Custom Renderer (PCL)
DEMO Implementing Custom Renders For Maps
Module Recap • Xamarin. Forms intró – Mi ez? – Követelmények • Xamarin. Forms vezérlőelemek • Kódosztási technikák – Portable Class Library-k – MVVM – Dependency Injection • Heritage Properties Xamarin. Forms alapokon • Xamarin. Forms Custom Renderer-ek
© 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics 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.
- Slides: 38