使用 Xamarin.Forms book 建立行動應用程式Creating Mobile Apps with Xamarin.Forms book

下載範例下載範例Download Sample Download the sample

本書使用 Xamarin.Forms 建立行動應用程式Charles petzold 的是了解如何撰寫 Xamarin.Forms 應用程式的指南。The book Creating Mobile Apps with Xamarin.Forms by Charles Petzold is a guide for learning how to write Xamarin.Forms applications. 唯一的先決條件是知識的C#程式設計語言。The only prerequisite is knowledge of the C# programming language. 本書提供廣泛的瀏覽至 Xamarin.Forms 的使用者介面,並且也涵蓋動畫、 MVVM、 觸發程序、 行為、 自訂版面配置、 自訂轉譯器及其他更多。The book provides an extensive exploration into the Xamarin.Forms user interface and also covers animation, MVVM, triggers, behaviors, custom layouts, custom renderers, and much more.

本書已在 2016 年春季發行,並且未在那之後更新。The book was published in the spring of 2016, and has not been updated since then. 有很多活頁簿中,仍有價值,但某些資料已過期,而且某些主題也無法再完全正確或已完成。There is much in the book that remains valuable, but some of the material is outdated, and some topics are no longer entirely correct or complete.

免費下載電子書Download eBook for free

下載您慣用的電子書的格式,從 Microsoft Virtual Academy:Download your preferred eBook format from Microsoft Virtual Academy:

您也可以下載個別的章節為 PDF 檔案。You can also download individual chapters as PDF files.

範例Samples

這些範例可在 github 上,並包含適用於 iOS、 Android 和通用 Windows 平台 (UWP) 專案。The samples are available on github, and include projects for iOS, Android, and the Universal Windows Platform (UWP). (Xamarin.Forms 已不再支援 Windows 10 行動裝置,但 Xamarin.Forms 應用程式將執行 Windows 10 桌面上)。(Xamarin.Forms no longer supports Windows 10 Mobile, but Xamarin.Forms applications will run on the Windows 10 desktop.)

章節摘要Chapter summaries

章節摘要可用於章資料表如下所示。Chapter summaries are available in the chapter table show below. 這些摘要說明的每一章中,內容,並包含數種類型的連結:These summaries describe the contents of each chapter, and include several types of links:

  • 連結的活頁簿 (位於頁面底部),實際的章節,以及相關文章Links to the actual chapters of the book (at the bottom of the page), and to related articles

  • 中的所有範例的連結 xamarin forms-活頁簿範例 GitHub 存放庫Links to all the samples in the xamarin-forms-book-samples GitHub repository

  • 如需更詳細說明的 Xamarin.Forms 類別、 結構、 屬性、 列舉和其他等等的 API 文件的連結Links to the API documentation for more detailed descriptions of Xamarin.Forms classes, structures, properties, enumerations, and so forth

這些摘要也會指出一章中的資料可能會當有點過時These summaries also indicate when material in the chapter might be somewhat outdated.

下載章節和摘要Download chapters and summaries

章節Chapter 完成文字Complete Text 總結Summary
第 1 章。Chapter 1. Xamarin.Forms 調整為何?How Does Xamarin.Forms Fit In? 下載 PDFDownload PDF 摘要Summary
第 2 章。Chapter 2. 應用程式剖析Anatomy of an App 下載 PDFDownload PDF 摘要Summary
第 3 章。Chapter 3. 更深入成文字Deeper into Text 下載 PDFDownload PDF 摘要Summary
第 4 章。Chapter 4. 捲動堆疊Scrolling the Stack 下載 PDFDownload PDF 摘要Summary
第 5 章。Chapter 5. 因應大小Dealing with Sizes 下載 PDFDownload PDF 摘要Summary
第 6 章。Chapter 6. 按下按鈕Button Clicks 下載 PDFDownload PDF 摘要Summary
第 7 章。Chapter 7. XAML vs。程式碼XAML vs. Code 下載 PDFDownload PDF 摘要Summary
第 8 章。Chapter 8. 程式碼和 XAML 搭配Code and XAML in Harmony 下載 PDFDownload PDF 摘要Summary
第 9 章。Chapter 9. 平台特定 API 呼叫Platform-Specific API Calls 下載 PDFDownload PDF 摘要Summary
第 10 章。Chapter 10. XAML 標記延伸XAML Markup Extensions 下載 PDFDownload PDF 摘要Summary
第 11 章。Chapter 11. 可繫結的基礎結構The Bindable Infrastructure 下載 PDFDownload PDF 摘要Summary
第 12 章。Chapter 12. 樣式Styles 下載 PDFDownload PDF 摘要Summary
第 13 章。Chapter 13. 點陣圖Bitmaps 下載 PDFDownload PDF 摘要Summary
第 14 章。Chapter 14. 絕對版面配置Absolute Layout 下載 PDFDownload PDF 摘要Summary
第 15 章。Chapter 15. 互動式介面The Interactive Interface 下載 PDFDownload PDF 摘要Summary
第 16 章。Chapter 16. 資料繫結Data Binding 下載 PDFDownload PDF 摘要Summary
第 17 章。Chapter 17. 掌控格線Mastering the Grid 下載 PDFDownload PDF 摘要Summary
第 18 章。Chapter 18. MVVMMVVM 下載 PDFDownload PDF 摘要Summary
第 19 章。Chapter 19. 集合檢視Collection Views 下載 PDFDownload PDF 摘要Summary
第 20 章。Chapter 20. 非同步與檔案 I/OAsync and File I/O 下載 PDFDownload PDF 摘要Summary
第 21 章。Chapter 21. 轉換Transforms 下載 PDFDownload PDF 摘要Summary
第 22 章。Chapter 22. 動畫Animation 下載 PDFDownload PDF 摘要Summary
第 23 章。Chapter 23. 觸發程序和行為Triggers and Behaviors 下載 PDFDownload PDF 摘要Summary
第 24 章。Chapter 24. 頁面巡覽Page Navigation 下載 PDFDownload PDF 摘要Summary
第 25 章。Chapter 25. 頁面變化Page Varieties 下載 PDFDownload PDF 摘要Summary
第 26 章。Chapter 26. 自訂配置Custom Layouts 下載 PDFDownload PDF 摘要Summary
第 27 章。Chapter 27. 自訂轉譯器Custom renderers 下載 PDFDownload PDF 摘要Summary
第 28 章。Chapter 28. 位置與地圖Location and Maps 下載 PDFDownload PDF 摘要Summary

本書已過期的方式Ways in which the book is outdated

因為發行使用 Xamarin.Forms 建立行動應用程式,多項新功能已新增至 Xamarin.Forms。Since the publication of Creating Mobile Apps with Xamarin.Forms, several new features have been added to Xamarin.Forms. 中的個別文章中所述的這些新功能Xamarin.Forms文件。These new features are described in individual articles in the Xamarin.Forms documentation.

其他的變更已經造成的某些活頁簿可能已過時的內容:Other changes have caused some of the content of the book to be outdated:

.NET standard 2.0 程式庫已取代的可攜式類別庫.NET Standard 2.0 libraries have replaced Portable Class Libraries

Xamarin.Forms 應用程式通常會使用程式庫共用不同的平台之間的程式碼。A Xamarin.Forms application generally uses a library to share code among the different platforms. 一開始,這是可攜式類別庫 (PCL)。Originally, this was a Portable Class Library (PCL). 有許多參考 Pcl 整個活頁簿和章節摘要。There are many references to PCLs throughout the book and the chapter summaries.

可攜式類別庫中已取代為.NET Standard 2.0 程式庫,本文所述.NET Standard 2.0 支援在 Xamarin.Forms 中The Portable Class Library has been replaced with a .NET Standard 2.0 library, as described in the article .NET Standard 2.0 Support in Xamarin.Forms. 所有範例程式碼活頁簿中已更新為使用.NET Standard 2.0 程式庫。All the sample code from the book has been updated to use .NET Standard 2.0 libraries.

大部分的活頁簿相關的可攜式類別庫中的角色中的資訊會保持相同的.NET Standard 2.0 程式庫。Most of the information in the book concerning the role of the Portable Class Library remains the same for a .NET Standard 2.0 library. 其中一個差異是只有 PCL 具有數值 「 設定檔。 」One difference is that only a PCL has a numeric "profile." 此外,還有一些優點,.NET Standard 2.0 程式庫。Also, there are some advantages to .NET Standard 2.0 libraries. 比方說,一章 20 Async 和檔案 I/O描述如何使用基礎平台來執行檔案 I/O。For example, Chapter 20, Async and File I/O describes how to use the underlying platforms for performing file I/O. 這不再是必要的。This is no longer necessary. .NET Standard 2.0 程式庫支援熟悉System.IO適用於所有的 Xamarin.Forms 平台的類別。The .NET Standard 2.0 library supports the familiar System.IO classes for all Xamarin.Forms platforms.

.NET Standard 2.0 程式庫也可讓 Xamarin.Forms 應用程式,以使用 HttpClient 透過網際網路存取的檔案而非 WebRequest 或其他類別。The .NET Standard 2.0 library also allows Xamarin.Forms applications to use HttpClient to access files over the Internet rather than WebRequest or other classes.

XAML 的角色具有更高The role of XAML has been elevated

使用 Xamarin.Forms 建立行動應用程式一開始會描述如何撰寫使用 C# 的 Xamarin.Forms 應用程式。Creating Mobile Apps with Xamarin.Forms begins by describing how to write Xamarin.Forms applications using C#. Extensible Application Markup Language (XAML) 不之前所引入第 7 章。XAML vs。程式碼The Extensible Application Markup Language (XAML) isn't introduced until Chapter 7. XAML vs. Code.

XAML 現在有更大的角色,在 Xamarin.Forms 中。XAML now has a much larger role in Xamarin.Forms. 與 Visual Studio 一起散發的 Xamarin.Forms 方案範本會建立以 XAML 為基礎的分頁檔。The Xamarin.Forms solution templates distributed with Visual Studio create XAML-based page files. 盡早使用 Xamarin.Forms 的開發人員應該先熟悉 XAML。A developer using Xamarin.Forms should become familiar with XAML as early as possible. 可延伸應用程式標記語言 (XAML) Xamarin.Forms 文件章節包含有關 XAML 可協助您開始的數個文件。The eXtensible Application Markup Language (XAML) section of the Xamarin.Forms documentation contains several articles about XAML to get you started.

支援的平台Supported platforms

Xamarin.Forms 不再支援 Windows 8.1 和 Windows Phone 8.1。Xamarin.Forms no longer supports Windows 8.1 and Windows Phone 8.1.

本書有時甚至會使參考_Windows 執行階段_。The book sometimes makes references to the Windows Runtime. 這是一個詞彙,包含用於數個版本的 Windows 和 Windows Phone 的 Windows API。This is a term that encompasses the Windows API used in several versions of Windows and Windows Phone. 較新版本的 Xamarin.Forms 會限制本身支援通用 Windows 平台,這 API 適用於 Windows 10 和 Windows 10 行動裝置。More recent versions of Xamarin.Forms restricts itself to supporting the Universal Windows Platform, which is the API for Windows 10 and Windows 10 Mobile.

.NET Standard 2.0 程式庫不支援任何版本的 Windows 10 行動裝置。A .NET Standard 2.0 library does not support any version of Windows 10 Mobile. 因此,使用.NET Standard 程式庫的 Xamarin.Forms 應用程式將不會執行 Windows 10 行動裝置版裝置上。Therefore, a Xamarin.Forms application using a .NET Standard library will not run on a Windows 10 Mobile device. Xamarin.Forms 應用程式繼續執行 Windows 10 desktop 版本 10.0.16299.0 和更新版本。Xamarin.Forms applications continue to run on the Windows 10 desktop, versions 10.0.16299.0 and above.

Xamarin.Forms 可預覽支援MacWPFGTK #,以及Tizen平台。Xamarin.Forms has preview support for the Mac, WPF, GTK#, and Tizen platforms.

章節摘要Chapter summaries

章節摘要包括有關 Xamarin.Forms 中的變更,因為本書所撰寫的資訊。The chapter summaries include information concerning changes in Xamarin.Forms since the book was written. 這些通常是備忘稿的形式:These are often in the form of notes:

注意

每個頁面上的提示會指出其中 Xamarin.Forms 有分歧活頁簿中所呈現的題材。Notes on each page indicate where Xamarin.Forms has diverged from the material presented in the book.

範例Samples

xamarin forms-活頁簿範例 GitHub 存放庫,原始的程式碼-從-書分支包含活頁簿與一致的程式範例。In the xamarin-forms-book-samples GitHub repository, the original-code-from-book branch contains program samples consistent with the book. 主要分支包含已升級至移除已被取代的 Api,並反映增強型的 Api 的專案。The master branch contains projects that have been upgraded to remove deprecated APIs and reflect enhanced APIs. 此外,Android 專案主要分支已升級適用於 Android透過 AppCompat Material Design和白色背景上通常會顯示黑色文字。In addition, the Android projects in the master branch have been upgraded for Android Material Design via AppCompat and will generally display black text on a white background.