Creating Mobile Apps with Xamarin.Forms
Total Page:16
File Type:pdf, Size:1020Kb
Creating Mobile Apps with Xamarin.Forms 2 Cross-platform C# programming for iOS, Android, and Windows Phone CHARLES PETZOLD PREVIEW EDITION This excerpt provides early content from a book currently in development and is still in draft format. See additional notice below. PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2015 Xamarin, Inc. All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. ISBN: 978-0-7356-9723-2 Microsoft Press books are available through booksellers and distributors worldwide. Please tell us what you think of this book at http://aka.ms/tellpress. This document is provided for informational purposes only and Microsoft makes no warranties, either express or implied, in this document. Information in this document, including URL and other Internet website references, is subject to change without notice. The entire risk of the use or the results from the use of this document remains with the user. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distrib- utors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under cop- yright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty/ Trade- marks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their re- spective owners. The example companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distrib- utors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Acquisitions and Project Editor: Devon Musgrave Editorial production: John Pierce, Flying Squirrel Press Cover illustration: Serena Zhang Table of contents Introduction ....................................................................................................................... viii Who should read this book ...................................................................................................................................................... viii Conventions and features in this book ................................................................................................................................ viii The 1st and 2nd Preview Editions ............................................................................................................................................... ix System requirements ..................................................................................................................................................................... ix Downloads: Code samples ............................................................................................................................................................ x Updating the code samples ..................................................................................................................................................... x Big changes coming for Windows Phone ........................................................................................................................ xi Acknowledgments .......................................................................................................................................................................... xi Free ebooks from Microsoft Press ........................................................................................................................................... xii We want to hear from you ......................................................................................................................................................... xii Chapter 1 How does Xamarin.Forms fit in? .............................................................. 1 Cross-platform mobile development ....................................................................................................................................... 2 The mobile landscape................................................................................................................................................................ 2 Problem 1: Different user-interface paradigms .............................................................................................................. 2 Problem 2: Different development environments ......................................................................................................... 3 Problem 3: Different programming interfaces ................................................................................................................ 3 Problem 4: Different programming languages ............................................................................................................... 3 The C# and .NET solution ............................................................................................................................................................. 4 A single language for all platforms ...................................................................................................................................... 5 Sharing code ................................................................................................................................................................................. 6 Introducing Xamarin.Forms ......................................................................................................................................................... 8 The Xamarin.Forms option ...................................................................................................................................................... 8 XAML support ............................................................................................................................................................................. 10 Platform specificity ................................................................................................................................................................... 12 A cross-platform panacea? .................................................................................................................................................... 12 Your development environment ............................................................................................................................................. 13 Table of contents iii Machines and IDEs ................................................................................................................................................................... 13 Devices and emulators ............................................................................................................................................................ 14 Installation ........................................................................................................................................................................................ 14 Creating an iOS app ................................................................................................................................................................. 15 Creating an Android app ....................................................................................................................................................... 15 Creating a Windows Phone app ......................................................................................................................................... 16 All ready? ...................................................................................................................................................................................... 16 Chapter 2 Anatomy of an app .................................................................................... 17 Say hello ............................................................................................................................................................................................ 17 Inside the files ................................................................................................................................................................................. 20 The iOS Project .........................................................................................................................................................................