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