1. Trang chủ
  2. » Kinh Doanh - Tiếp Thị

Creating mobile apps with xamarin forms, preview edition 2 2015

453 8 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Creating Mobile Apps with Xamarin.Forms Cross-platform C# programming for iOS, Android, and Windows Phone CHARLES PETZOLD www.it-ebooks.info 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 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/EN-US.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 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 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 Editorial production: John Pierce, Flying Squirrel Press Cover illustration: Serena Zhang www.it-ebooks.info 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 How does Xamarin.Forms fit in? Cross-platform mobile development The mobile landscape Problem 1: Different user-interface paradigms Problem 2: Different development environments Problem 3: Different programming interfaces Problem 4: Different programming languages The C# and NET solution A single language for all platforms Sharing code Introducing Xamarin.Forms The Xamarin.Forms option XAML support .10 Platform specificity 12 A cross-platform panacea? 12 Your development environment .13 www.it-ebooks.info 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 Anatomy of an app 17 Say hello 17 Inside the files 20 The iOS Project 23 The Android project 23 The Windows Phone project 24 Nothing special! 25 PCL or SAP? 25 Labels for text 27 Include padding on the page 31 Include padding just for iOS (Shared Asset Project only) 32 Include padding just for iOS (PCL or SAP) 33 Center the label within the page 35 Center the text within the label 37 Chapter Deeper into text 38 Wrapping paragraphs 38 Text and background colors 40 The Color structure 42 Font sizes and attributes 46 Formatted text 47 Chapter Scrolling the stack 54 Stacks of views 54 Scrolling content 58 www.it-ebooks.info Table of contents iv The Expands option 64 Frame and BoxView 68 A ScrollView in a StackLayout? 76 Chapter Dealing with sizes 81 Pixels, points, dps, DIPs, and DIUs 81 Metrical sizes 88 Estimated font sizes 89 Fitting text to available size .92 A fit-to-size clock 96 Empirically fitting text 98 Chapter Button clicks 103 Processing the click 103 Sharing button clicks 106 Anonymous event handlers 109 Distinguishing views with IDs 111 Saving transient data 114 Chapter XAML vs code 121 Properties and attributes 122 Property-element syntax 126 Adding a XAML page to your project 130 Platform specificity in the XAML file 135 The content property attribute 139 Formatted text 141 Chapter Code and XAML in harmony 145 Passing arguments 145 Constructors with arguments 145 Can I call methods from XAML? 148 The x:Name attribute 150 Custom XAML-based views 156 Events and handlers 160 www.it-ebooks.info Table of contents v Tap gestures 163 Chapter Platform-specific API calls 170 Preprocessing in the Shared Asset Project 170 Parallel classes and the Shared Asset Project 173 DependencyService and the Portable Class Library 175 Platform-specific sound rendering .179 Chapter 10 XAML markup extensions 186 The code infrastructure .186 Accessing static members 188 Resource dictionaries 194 StaticResource for most purposes 195 A tree of dictionaries .201 DynamicResource for special purposes 205 Lesser-used markup extensions .208 A custom markup extension 209 Chapter 11 The bindable infrastructure 214 The Xamarin.Forms class hierarchy 215 A peek into BindableObject and BindableProperty 221 Defining bindable properties 228 The generic Create method 233 The read-only bindable property .234 Chapter 12 Styles 240 The basic Style 240 Styles in code .246 Style inheritance 247 Implicit styles 252 Dynamic styles 257 Device styles 264 Chapter 13 Bitmaps 269 Platform-independent bitmaps .270 www.it-ebooks.info Table of contents vi Fit and fill 273 Embedded resources 275 More on sizing 281 Browsing and waiting 292 Streaming bitmaps 296 Accessing the streams 297 Generating bitmaps at run time 299 Platform-specific bitmaps 303 Bitmap resolutions 305 Toolbars and their icons 312 Button images 319 Chapter 14 Absolute layout 322 AbsoluteLayout in code 323 Attached bindable properties 328 Proportional sizing and positioning 332 Working with proportional coordinates 334 AbsoluteLayout and XAML 339 Overlays 343 Some fun 346 Chapter 15 The interactive interface 355 View overview 355 Slider and Stepper 356 Slider basics 356 Common pitfalls 359 Slider color selection 361 The Stepper difference 365 Switch and CheckBox 368 Switch basics 368 A traditional CheckBox 370 Typing text 375 www.it-ebooks.info Table of contents vii Keyboard and focus .376 Choosing the keyboard 377 Entry properties and events 379 The Editor difference .385 The SearchBar 389 Date and time selection 394 The DatePicker 395 The TimePicker (or is it a TimeSpanPicker?) 398 Chapter 16 Data binding 402 Binding basics .402 Code and XAML 404 Source and BindingContext 407 The binding mode .414 String formatting 419 Why is it called “Path”? 422 Binding value converters 425 Bindings and custom views .433 www.it-ebooks.info Introduction This is the second 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 it’s not complete It has only 16 chapters and doesn’t cover some important topics The final edition of the book will probably be published in the summer of 2015 All information about this book can be found on the book’s home page at: http://developer.xamarin.com/guides/cross-platform/xamarin-forms/creating-mobile-apps-xamarin-forms/ 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 programmers started with these platforms or in constructing a prototype or proof-of-concept application This book assumes that you know C# and are familiar 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 Conventions and features in this book This book has just a few typographical conventions:  All programming elements referenced in the text—including 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 MonkeyTap www.it-ebooks.info Introduction ix The 1st and 2nd Preview Editions 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 at the Xamarin.Forms Framework link on this page: http://api.xamarin.com/ The first Preview Edition of this book was published in October 2014 to coincide with the Xamarin Evolve conference It contained six chapters but no coverage of XAML This second Preview Edition was reconceived to contain shorter and more focused chapters After the book establishes a solid foundation in code-only Xamarin.Forms programning, XAML is introduced in Chapter 7, and from that point on, XAML is used to define the user interface of most of the sample programs This Preview Edition unfortunately ends without covering some essential topics The most obvious missing topics include the Grid, collection views such as ListView, page navigation, triggers, behaviors, and maps However, it is our intention to publish chapters online just about as quickly as I can write them New chapters will appear on the Xamarin webpage devoted to this book System requirements This book assumes that you’ll be using Xamarin.Forms to write applications that simultaneously target all three supported mobile platforms—iOS, Android, and Windows Phone However, it’s very likely that many readers will be targeting only one or two platforms in their Xamarin.Forms solutions The platforms you target—and the Xamarin Platform package you purchase—govern your hardware and software requirements For targeting iOS devices, you’ll need a Mac installed with Apple Xcode as well as the Xamarin Platform, which includes Xamarin Studio For targeting Windows Phone, you’ll need Visual Studio 2012 or later (not an Express Edition) on a PC, and you’ll 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 are accessible via WiFi You can target Android devices from Visual Studio on the PC or from Xamarin Studio on either the PC or Mac Chapter has more details on the various configurations you can use and resources for additional information and support My setup for creating this book consisted of a Microsoft Surface Pro (with external monitor, keyboard, and mouse) installed with Visual Studio 2013 and the Xamarin Platform, connected by WiFi with a MacBook Pro installed with Xcode and the Xamarin Platform All the screen shots in this book show an iPhone, an Android phone, and a Windows Phone in that order The three devices shown in these screen shots reflect my setup and hardware:  The iPhone simulator on the MacBook Pro running iOS 8.2 www.it-ebooks.info ... How does Xamarin. Forms fit in? Introducing Xamarin. Forms On May 28 , 20 14, Xamarin introduced Xamarin. Forms as part of a collection of enhancements to the Xamarin platform dubbed Xamarin Xamarin.Forms... in late March 20 15 with version 1.4.0 of Xamarin. Forms The source code of these samples is hosted on a repository on GitHub: https://github.com /xamarin/ xamarin-forms-book -preview- 2/ You can clone... using Xamarin. iOS or Xamarin. Android, that’s not a problem with Xamarin. Forms, and you’ll need to solve that problem before using Xamarin. Forms Creating an iOS app If you’re interested in using Xamarin. Forms

Ngày đăng: 26/09/2021, 20:15

Xem thêm:

Mục lục

    Who should read this book

    Conventions and features in this book

    The 1[sup(st)] and 2[sup(nd)] Preview Editions

    Updating the code samples

    Big changes coming for Windows Phone

    Free ebooks from Microsoft Press

    We want to hear from you

    Problem 1: Different user-interface paradigms

    Problem 2: Different development environments

    Problem 3: Different programming interfaces

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w