Xamarin Mobile Application Development: Cross-Platform C# and Xamarin.Forms Fundamentals

Book description

Xamarin Mobile Application Development is a hands-on Xamarin.Forms primer and a cross-platform reference for building native Android, iOS, and Windows Phone apps using C# and .NET. This book explains how to use Xamarin.Forms, Xamarin.Android, and Xamarin.iOS to build business apps for your customers and consumer apps for Google Play and the iTunes App Store.

Learn how to leverage Xamarin.Forms for cross-platform development using the most common UI pages, layouts, views, controls, and design patterns. Combine these with platform-specific UI to craft a visually stunning and highly interactive mobile user experience.

Use Xamarin.Forms to data bind your UI to both data models and to view models for a Model-View-ViewModel (MVVM) implementation. Use this book to answer the important question: Is Xamarin.Forms right for my project?

Platform-specific UI is a key concept in cross-platform development, and Xamarin.Android and Xamarin.iOS are the foundation of the Xamarin platform. Xamarin Mobile Application Development will cover how to build an Android app using Xamarin.Android and an iOS app using Xamarin.iOS while sharing a core code library.

SQLite is the database-of-choice for many Xamarin developers. This book will explain local data access techniques using SQLite.NET and ADO.NET. Build a mobile data access layer (DAL) using SQLite and weigh your options for web services and enterprise cloud data solutions.

This book will show how organize your Xamarin code into a professional-grade application architecture. Explore solution-building techniques from starter-to-enterprise to help you decouple your functional layers, manage your platform-specific code, and share your cross-platform classes for code reuse, testability, and maintainability.

Also included are 250+ screenshots on iOS, Android, and Windows Phone and 200+ C# code examples with downloadable C# and XAML versions available from Apress.com.

This comprehensive recipe and reference book addresses one of the most important and vexing problems in the software industry today: How do we effectively design and develop cross-platform mobile applications?

Table of contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. Foreword
  8. Additional Foreword
  9. About the Author
  10. About the Technical Reviewer
  11. Acknowledgments
  12. Introduction
  13. Chapter 1: Mobile Development Using Xamarin
    1. What Is Xamarin?
      1. Wrapped Native APIs
      2. Development Environments
      3. UI Designers
    2. What’s Old: Familiar C# and .NET Techniques
    3. What’s New: Mobile Development Techniques
      1. Mobile UI
        1. Xamarin.Forms and Platform-Specific UI
        2. Mobile UI Design
        3. Xamarin.Forms Custom Renderers
      2. Data Access Layer
      3. Local Data Access Using SQLite
      4. Data Binding
      5. Cross-platform Development
    4. Summary
  14. Chapter 2: Building Mobile User Interfaces
    1. Understanding Xamarin.Forms
      1. Xamarin.Forms Solution Architecture
    2. Understanding the Platform-Specific UI Approach
      1. Platform-specific UI Solution Architecture
      2. Xamarin.Android
      3. Xamarin.iOS
      4. Windows Phone SDK
    3. Choosing Xamarin.Forms or a Platform-Specific UI
      1. Use Both Approaches with Custom Renderers
    4. Exploring the Elements of Mobile UIs
    5. Using the Xamarin.Forms UI
      1. Page
      2. Layout
      3. View
    6. Creating a Xamarin.Forms Solution
      1. Xamarin.Forms Shared Code
        1. Application Lifecycle Methods: OnStart, OnSleep, and OnResume
        2. Building Pages Using ContentPage
      2. Xamarin.Android
      3. Xamarin.iOS
      4. Windows Phone Application
      5. Core Library
      6. Setting the App’s Main Page
    7. Adding Xamarin.Forms Views
      1. Label View
      2. Placing Views Using StackLayout
      3. Background Color and Font Color
      4. Using Fonts
      5. Using Platform-Specific Fonts
      6. Button View
      7. Setting View Alignment and Size: HorizontalOptions and VerticalOptions
        1. Justification with LayoutOptions
        2. AndExpand Pads with Space
      8. Entry View for Text Input
      9. BoxView
      10. Image View
        1. Source Property
        2. Local Images
        3. Image Sizing: Aspect Property
        4. Making an Image Clickable with a GestureRecognizer
      11. Finalizing the StackLayout
      12. ScrollView
      13. Assigning the ContentPage.Content Property
      14. Padding Around the Entire Page
      15. CODE COMPLETE: Adding Xamarin.Forms Views
    8. Summary
  15. Chapter 3: UI Design Using Layouts
    1. Understanding Custom Controls
    2. Using Xamarin.Forms Layouts
      1. StackLayout
        1. Padding Around the Entire Layout
        2. Stacking with Vertical Orientation
        3. Stacking with Horizontal Orientation
        4. Nesting Layouts
        5. Expanding and Padding Views by Using LayoutOptions
        6. CODE COMPLETE: StackLayout
      2. RelativeLayout
        1. Setting View Location and Size
        2. Using Constraints
        3. CODE COMPLETE: RelativeLayout
      3. AbsoluteLayout
        1. Creating Bounding Objects with SetLayoutBounds
        2. Binding to the Bounding Object by Using SetLayoutFlags
        3. CODE COMPLETE: AbsoluteLayout
      4. Grid
        1. Sizing Rows and Columns
        2. Sizing to Fit Views
        3. Setting Exact Size
        4. Expanding Views to Fit Available Space
        5. Expanding Views Proportionally
        6. Creating Multicell Views
        7. Padding Between Cells
        8. CODE COMPLETE: Grid
      5. ContentView
        1. CODE COMPLETE: ContentView
      6. Frame
    3. Using Android Layouts
      1. LinearLayout
        1. Using Activities to Display Layouts
        2. Creating Layouts in Code
        3. Working with Nested Layouts
      2. RelativeLayout
      3. TableLayout
      4. GridLayout
        1. Filling Rows Left to Right with Horizontal Orientation
        2. Filling Columns Top to Bottom with Vertical Orientation
        3. Specifying Rows and Columns
        4. Creating Multicell Views
        5. Creating a Dynamic Grid of Images
      5. FrameLayout
      6. Fragments
    4. Using iOS Layouts
      1. Using AutoLayout
        1. Add Constraints by Using Visual Format Language
      2. Using Frames
    5. Summary
  16. Chapter 4: User Interaction Using Controls
    1. Xamarin.Forms Views
      1. Picker
      2. DatePicker
      3. TimePicker
      4. Stepper
      5. Slider
      6. Switch
      7. Scale, Rotation, Opacity, Visibility, and Focus
      8. CODE COMPLETE: Xamarin.Forms Views
    2. Android Controls
      1. Spinner
        1. CODE COMPLETE: Spinner
      2. DatePicker
        1. Creating a Modal DatePicker by Using DatePickerDialog
        2. CODE COMPLETE: DatePickerExample
      3. TimePicker
      4. SeekBar
      5. CheckBox
      6. Switch
        1. Customizing with a Title, Switch Text, and State
      7. RadioButton
      8. CODE COMPLETE: Android Controls
    3. iOS Controls
      1. UIPickerView
        1. Making a UIPickerView into a Pop-up
        2. CODE COMPLETE: UIPickerView
      2. UIDatePicker
        1. Making a UIDatePicker into a Pop-up
        2. Specify Which Fields to Display
        3. CODE COMPLETE: UIDatePicker
        4. UIStepper
        5. UISlider
        6. CheckBox: Use UISwitch or MonoTouch.Dialog
        7. UISwitch
        8. CODE COMPLETE: iOS Controls
    4. Summary
  17. Chapter 5: Making a Scrollable List
    1. Data Adapters
    2. Xamarin.Forms ListView
      1. Binding to a List of Strings
      2. Selecting an Item
      3. Binding to a Data Model
        1. CODE COMPLETE: Binding to a Data Model
      4. Adding an Image
      5. Customizing List Rows
        1. CODE COMPLETE: Customizing List Rows
      6. Adding Buttons
        1. Using Button Views
        2. Using Context Actions
      7. Grouping Headers
      8. Customizing the Group Header
      9. Creating a Jump List
      10. ListViews Scroll Automatically
      11. Optimizing Performance
    3. Android ListView
      1. Using ListActivity
      2. Binding to an Array of Strings
      3. Selecting an Item
        1. Multiple Selection
      4. Binding to a Data Model
        1. Data Model
        2. Adapter
        3. Activity
      5. Optimizing Performance
      6. Using the Built-in Row Views
      7. Customizing List Rows
        1. Selecting an Item in a Customized Row
        2. CODE COMPLETE: Customizing List Rows
      8. Grouping Headers
    4. iOS UITableView
      1. Binding to an Array of Strings
      2. Selecting an Item
        1. Multiple Selection
      3. Binding to a Data Model
        1. Data Model
        2. Adapter
        3. View Controller
      4. Using Built-in Row Views
      5. Cell Separators
      6. Customizing List Rows
      7. Grouping Headers
        1. CODE COMPLETE: Grouping Adapter
        2. CODE COMPLETE: Grouping View Controller
      8. Highlighting Groups Using Table Styles
      9. Accessorizing List Rows
        1. Selecting an Accessory
      10. Optimizing Performance
      11. An Alternative Approach to Lists: UITableViewController
    5. Summary
  18. Chapter 6: Navigation
    1. Navigation Patterns
      1. Hierarchical
      2. Modal
      3. State Management
    2. Xamarin.Forms Navigation
      1. Hierarchical Navigation Using NavigationPage
        1. Pushing and Popping Screens on the Navigation Stack
        2. Setting the Page Title
        3. Customizing the Navigation Bar
        4. Handling the Back Button
        5. Creating a Drop-down Menu
      2. Modal
        1. Full-Page Modal Using NavigationPage
        2. User Notification Using Alerts
        3. Pop-up Menu Using Action Sheets
      3. Managing State
        1. Passing Data into Page Parameters
        2. Disk Persistence Using the Properties Dictionary
        3. Using a Static Global Class
        4. Using a Static Property on the Application Object
      4. Drill-down Lists
        1. Using ListView by Item
        2. CODE COMPLETE: Drill-down List
        3. Using ListView by Page
        4. Using TableView for Grouping Pages
      5. Navigation Drawer Using MasterDetailPage
      6. Tabs Using TabbedPage
        1. Creating Data-Bound Tabs
        2. Putting NavigationPages Inside a TabbedPage
      7. Springboard
        1. Making Icons Tappable by Using Gesture Recognizers
      8. Carousel Using CarouselPage
    3. Android Navigation
      1. Starting New Activities Using Intents
      2. Hierarchical Navigation Using the Toolbar
        1. Handling the Up Button
        2. Adding a Pop-up Menu
        3. Customize the Toolbar
      3. Using the Navigation Bar
        1. Handling the Back Button
      4. Fragments
      5. Modal Navigation
        1. Creating Modals Using DialogFragment
        2. Creating Alerts Using DialogFragment
        3. Modal Layouts Using AlertDialog
        4. PopupMenu
      6. Managing State Using Bundles
        1. Passing Strings
        2. Passing Objects
        3. Creating a Bundle
        4. Using Static Global Classes and StartActivityForResult
      7. Drill-down List
        1. Using ListView by Page
        2. Using ListView by Item
        3. Using ListView with a Toolbar
      8. Navigation Drawer
      9. Tabs Using ActionBar
        1. CODE COMPLETE: TabMenuActivity.cs
    4. iOS Navigation
      1. Using Storyboards, Scenes, and Segues
      2. Using Nibs
      3. Hierarchical Navigation
        1. Using UINavigationController
        2. Using the Push Segue or PushViewController
        3. Customizing UINavigationController
      4. Modal Navigation
        1. Using the Modal Segue or PresentViewController
        2. Alerts and User Notifications Using UIAlertController
        3. Pop-up Menus Using UIAlertController
      5. Managing State
        1. Using the PrepareForSegue Method
        2. Using UIViewController Public Properties
        3. Using the UIViewController Constructor Parameters
      6. Drill-down List Using UINavigationController
      7. Navigation Drawer Using Components
      8. Tabs Using UITabBarController
    5. Summary
  19. Chapter 7: Data Access with SQLite and Data Binding
    1. What Is SQLite?
    2. What Is SQLite.NET?
    3. Data Binding
    4. Xamarin.Forms Data Binding
      1. Binding to a Data Model
      2. Using INotifyPropertyChanged
      3. CODE COMPLETE: Using INotifyPropertyChanged
      4. Understanding ViewModels and MVVM
      5. Binding to ViewModels and Data Models
        1. Create a ViewModel That Implements INotifyPropertyChanged
        2. Implement INotifyPropertyChanged in Your Data Model
      6. Binding a Read-Only ListView
      7. Binding an Editable ListView
        1. Adding and Deleting Rows
        2. Editing Properties
        3. Binding to a View Model
        4. CODE COMPLETE: Binding an Editable ListView
      8. Binding a View to Another View
    5. Using SQLite.NET
      1. Installing SQLite on Windows Phone
      2. Creating a Database
      3. Building the Database Path
        1. Connect by Using Shared Projects
        2. Connect by Using Portable Class Libraries
        3. Connect in Android
        4. Connect in iOS
        5. Connect in Windows Phone
      4. Creating a Table
        1. Using Attributes
        2. Inserting and Deleting Rows
        3. Getting Rows
        4. Updating Rows
        5. Locking Rows
      5. Creating the Data Access Layer
        1. Creating a Repository
        2. Managing the Repository
        3. Adding Methods to the Repository
      6. CODE COMPLETE: Creating a DAL by Using SQLite.NET
    6. Using ADO.NET
      1. Creating a Database
      2. Creating a Table
      3. Executing SQL Statements
    7. Database Creation Options
    8. Web Services
    9. Enterprise Cloud Data Solutions
      1. Microsoft Azure
      2. IBM MobileFirst Platform Foundation
      3. Amazon Web Services (AWS)
    10. Summary
  20. Chapter 8: Custom Renderers
    1. When to Use a Custom Renderer
    2. Creating and Using a Custom Renderer
    3. Preparing the Custom Element
    4. Creating the Custom Renderer
    5. Android Custom Renderer
      1. CODE COMPLETE: Android Custom Renderer
    6. iOS Custom Renderer
      1. CODE COMPLETE: iOS Custom Renderer
    7. Windows Phone Custom Renderer
      1. CODE COMPLETE: Windows Phone Custom Renderer
    8. Which Renderer and View Do You Customize?
    9. Summary
  21. Chapter 9: Cross-Platform Architecture
    1. Shared Code and Platform-Specific Code
    2. Handling Divergence
    3. Xamarin.Forms Solution Architecture
    4. Platform-Specific Solution Architecture
    5. Core Library
    6. Portable Class Libraries (PCL)
    7. Dependency Injection
      1. Using DependencyService
        1. Creating an Interface
        2. Android Implementation
        3. iOS Implementation
        4. Windows Phone Implementation
        5. Invocation of the Platform-Specific Class
        6. CODE COMPLETE: Using DependencyService
      2. Third-Party and Open Source DI Containers
    8. Shared Projects
      1. Conditional Compilation
      2. File Linking
      3. Partial Classes and Methods
    9. Handling Version Divergence
    10. Summary
  22. Epilogue: The Art of Xamarin App Development
  23. Index

Product information

  • Title: Xamarin Mobile Application Development: Cross-Platform C# and Xamarin.Forms Fundamentals
  • Author(s):
  • Release date: July 2015
  • Publisher(s): Apress
  • ISBN: 9781484202142