Creating Mobile Apps with Xamarin.Forms
Cross-platform C# programming for iOS, Android, and Windows Phone
PREVIEW EDITION
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 2014 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-9725-6
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 authors 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 distributors 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 copyright, 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/Trademarks/ENUS.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective 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 authors 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 distributors 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
Cover illustration: Serena Zhang
Table of contents
Introduction
This is a Preview Edition of a book about writing applications for Xamarin.Forms, the exciting new mobile development platform for iOS, Android, and Windows Phone unveiled by Xamarin in May 2014. Xamarin.Forms lets you write shared user-interface code in C# and XAML (the eXtensible Application Markup Language) that maps to native controls on these three platforms.
This book is a Preview Edition because its not complete. It has only six chapters. We anticipate that the final version of the book will have at least half a dozen additional chapters and that the chapters in this Preview Edition might be fleshed out, enhanced, or completely reconceived. The final edition of the book will probably be published in the spring of 2015.
Who should read this book
This book is for C# programmers who want to write applications for the three most popular mobile platforms: iOS, Android, and Windows Phone with a single code base. Xamarin.Forms also has applicability for those programmers who want eventually to use C# and the Xamarin.iOS and Xamarin.Android libraries to target the native application programming interfaces (APIs) of these platforms. Xamarin.Forms can be a big help in getting started with these platforms or in constructing a prototype or proof-of-concept application.
Assumptions
This book assumes that you know C# and have some familiarity with the use of the .NET Framework. However, when I discuss some C# and .NET features that might be somewhat new to recent C# programmers, I adopt a somewhat slower pace. In particular, the introduction of the async
keyword and await
operator in follows a discussion that shows how to do asynchronous programming using traditional callback methods.
Organization of this book
This book is intended as a tutorial to learn Xamarin.Forms programming. It is not a replacement for the online API documentation, which can be found here under the heading Xamarin.Forms Framework on this page: http://api.xamarin.com/.
This Preview Editions explores some of the basics of Xamarin.Forms programming, including the use of Label
, Button
, and StackLayout
.
, however, I tried to do something a little different: These chapters show the progressive step-by-step development of a small Xamarin.Forms application. Despite the simplicity of this program, it is in many ways a real application, and requires essential real-app facilities such as file I/O and application lifecycle handling, both of which turned out to be somewhat more challenging than I originally anticipated. Im curious to hear whether these two chapters work or not. See the section below on submitting feedback to us.
.
Conventions and features in this book
This book has just a few typographical conventions:
All programming elements referenced in the textincluding classes, methods, properties, variable names, etc.are shown in a monospaced font, such as the StackLayout
class.
Items that appear in the user interface of Visual Studio or Xamarin Studio, or the applications discussed in these chapters, appear in boldface, such as the Add New Project dialog.
Application solutions and projects also appear in boldface, such as ColorScroll.
System requirements
This book assumes that youll be using Xamarin.Forms to write applications that simultaneously target all three supported mobile platformsiOS, Android, and Windows Phone. However, its very likely that many readers will be targeting only one or two platforms in their Xamarin.Forms solutions. The platforms you targetand the Xamarin Platform package you purchasegovern your hardware and software requirements. For targeting iOS devices, youll need a Mac installed with Apple XCode as well as the Xamarin Platform, which includes Xamarin Studio. For targeting Windows Phone, youll need Visual Studio 2012 or 2013 (not an Express Edition) on a PC, and youll need to have installed the Xamarin Platform.
However, you can also use Visual Studio on the PC to target iOS devices if the Mac with XCode and the Xamarin Platform is accessible via WiFi. You can target Android devices from Visual Studio on the PC or from Xamarin Studio on either the PC or Mac.