Xamarin.Forms Projects

Book description

Explore Xamarin.Forms to develop dynamic applications

Key Features

  • Explore SQLite through Xamarin to store locations for various location-based applications
  • Make a real-time serverless chat service by using Azure SignalR service
  • Build Augmented Reality application with the power of UrhoSharp together with ARKit and ARCore

Book Description

Xamarin.Forms is a lightweight cross-platform development toolkit for building applications with a rich user interface.

In this book you'll start by building projects that explain the Xamarin.Forms ecosystem to get up and running with building cross-platform applications. We'll increase in difficulty throughout the projects, making you learn the nitty-gritty of Xamarin.Forms offerings. You'll gain insights into the architecture, how to arrange your app's design, where to begin developing, what pitfalls exist, and how to avoid them. The book contains seven real-world projects, to get you hands-on with building rich UIs and providing a truly cross-platform experience. It will also guide you on how to set up a machine for Xamarin app development. You'll build a simple to-do application that gets you going, then dive deep into building advanced apps such as messaging platform, games, and machine learning, to build a UI for an augmented reality project.

By the end of the book, you'll be confident in building cross-platforms and fitting Xamarin.Forms toolkits in your app development. You'll be able to take the practice you get from this book to build applications that comply with your requirements.

What you will learn

  • Set up a machine for Xamarin development
  • Get to know about MVVM and data bindings in Xamarin.Forms
  • Understand how to use custom renderers to gain platform-specific access
  • Discover Geolocation services through Xamarin Essentials
  • Create an abstraction of ARKit and ARCore to expose as a single API for the game
  • Learn how to train a model for image
  • classification with Azure Cognitive Services

Who this book is for

This book is for mobile application developers who want to start building native mobile apps using the powerful Xamarin.Forms and C#. Working knowledge of C#, .NET, and Visual Studio is required.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Publisher resources

View/Submit Errata

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Xamarin.Forms Projects
  3. Dedication
  4. www.PacktPub.com
    1. Why subscribe?
    2. Packt.com
  5. Foreword
  6. Contributors
    1. About the authors
    2. About the reviewer
    3. Packt is searching for authors like you
  7. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  8. Introduction to Xamarin
    1. Native applications
    2. Xamarin and Mono
      1. Code sharing
      2. Using existing knowledge
    3. Xamarin.iOS
    4. Xamarin.Android
    5. Xamarin.Mac
    6. Xamarin.Forms
      1. The architecture of Xamarin.Forms
      2. Defining a user interface using XAML
        1. Defining a Label control
        2. Creating a page in XAML
        3. Creating a page in C#
        4. XAML or C#?
      3. Xamarin.Forms versus traditional Xamarin
        1. When to use Xamarin.Forms
    7. Setting up a development machine
      1. Setting up a Mac
        1. Installing Xcode
        2. Installing Visual Studio
        3. Configuring the Android emulator
      2. Setting up a Windows machine
        1. Installing Xamarin for Visual Studio
        2. Pairing Visual Studio with a Mac
        3. Configuring an Android emulator and hardware acceleration
        4. Configuring UWP developer mode
    8. Summary
  9. Building Our First Xamarin.Forms App
    1. Technical requirements
    2. An overview of the project
    3. Beginning the project
      1. Setting up the project
        1. Creating the new project
        2. Examining the files
          1. DoToo
          2. DoToo.Android
          3. DoToo.iOS
          4. DoToo.UWP
        3. Updating the Xamarin.Forms packages
        4. Removing the MainPage file
      2. Creating a repository and a TodoItem model
        1. Defining a to-do list item
        2. Creating a repository and its interface
        3. Connecting SQLite to persist data
          1. Adding the SQLite NuGet package
          2. Updating the TodoItem class
          3. Creating a connection to the SQLite database
          4. Implementing the Get, Add, and Update methods
      3. Using MVVM – creating Views and ViewModels
        1. Defining a ViewModel base class
        2. Introducing PropertyChanged.Fody
        3. Creating the MainViewModel
        4. Creating the TodoItemViewModel
        5. Creating the ItemViewModel
        6. Creating the MainView
        7. Creating the ItemView
        8. Wiring up a dependency injection through Autofac
          1. Adding a reference to Autofac
          2. Creating the resolver
          3. Creating the bootstrapper
          4. Adding a bootstrapper on iOS
          5. Adding a bootstrapper in Android
          6. Adding a bootstrapper in UWP
        9. Making the app run
      4. Adding data bindings
        1. Navigating from the MainView to the ItemView to add a new item
        2. Adding new items to the list
        3. Binding the ListView in the MainView
        4. Creating a ValueConverter for the item status
          1. Using the ValueConverter
        5. Navigating to an item using a command
        6. Marking an item as complete using a command
        7. Creating the filter toggle function using a command
      5. Laying out contents
        1. Setting an application-wide background color
        2. Laying out the MainView and ListView items
          1. The filter button
          2. Touching up the ListView
    4. Summary
  10. A Matchmaking App with a Rich UX Using Animations
    1. Technical requirements
    2. Project overview
    3. Creating the matchmaking app
      1. Creating the project
        1. Creating the new project
        2. Updating the Xamarin.Forms NuGet packages
      2. Designing the MainPage file
      3. Creating the Swiper control
        1. Creating the control
        2. Defining the main grid
        3. Adding a content view for the photo
        4. Creating the DescriptionGenerator
        5. Creating a picture class
        6. Binding the picture to the control
          1. Setting the source
          2. Controlling the loading label
        7. Handling pan gestures
      4. Testing the control
      5. Creating decision zones
        1. Extending the grid
          1. Adding the StackLayout for liking photos
          2. Adding the StackLayout for denying photos
        2. Determining the screen size
        3. Adding a clamp function
        4. Adding code to calculate the state
          1. Defining a method for calculating the state
          2. Wiring up the pan state check
        5. Adding exit logic
          1. Checking if the image should exit
          2. Removing the image
          3. Updating PanCompleted
        6. Adding events to the control
          1. Declaring two events
          2. Raising the events
      6. Wiring up the Swiper control
        1. Adding images
          1. Adding initial photos
          2. Making the call from the constructor
        2. Adding count labels
        3. Subscribing to events
          1. Adding methods to update the GUI and respond to events
          2. Wiring up events
    4. Summary
  11. Building a Location Tracking App Using GPS and Maps
    1. Technical requirements
    2. Project overview
    3. Getting started
    4. Building the MeTracker app
      1. Creating a repository to save the location of the users
        1. Creating a model for the location data
        2. Creating the repository
      2. Xamarin.Essentials
        1. Installing the NuGet package
        2. Configuring Xamarin.Essentials on Android
      3. Creating a service for location tracking
      4. Setting up the app logic
        1. Creating a view with a map
        2. Creating a ViewModel
        3. Creating a resolver
        4. Creating the bootstrapper
          1. Creating the iOS bootstrapper
          2. Creating the Android bootstrapper
        5. Setting the MainPage
      5. Background location tracking on iOS
        1. Enabling location updates in the background
        2. Getting permissions to use the location of the user
        3. Subscribing to location updates
      6. Background location tracking with Android
        1. Adding the required permissions to use the location of the user
        2. Creating a background job
        3. Scheduling a background job
        4. Subscribing to location updates
      7. Creating a heat map
        1. Adding a GetAll method to the LocationRepository
        2. Preparing the data for visualization
        3. Creating custom renderers
          1. Creating a custom control for the map
          2. Creating a custom renderer to extend the map in the iOS app
          3. Creating a custom renderer to extend the map in the Android app
      8. Refreshing the map when resuming the app
    5. Summary
  12. Building a Weather App for Multiple Form Factors
    1. Technical requirements
    2. Project overview
    3. Getting started
    4. Building the weather app
      1. Creating models for the weather data
        1. Adding the weather API models manually
        2. Adding the app-specific models
        3. Adding the ForecastItem model
        4. Adding the Forecast model
      2. Creating a service for fetching the weather data
      3. Configuring the applications to use location services
        1. Configuring the iOS app to use location services
        2. Configuring the Android app to use location services
        3. Configuring the UWP app to use location services
      4. Creating the ViewModel class
        1. Getting the weather data
        2. Grouping the weather data
      5. Creating a Resolver
      6. Creating a bootstrapper
      7. Creating a RepeaterView based on a FlexLayout
      8. Creating the view for tablets and desktop computers
        1. Using RepeaterView
        2. Adding a toolbar item to refresh the weather data
          1. Adding a loading indicator
        3. Setting a background image
      9. Creating the view for phones
        1. Using a grouped ListView
        2. Adding pull to refresh functionality
      10. Navigating to different views based on the form factor
      11. Handling states with VisualStateManager
        1. Creating a behavior to set state changes
    5. Summary
  13. Setting up a Backend for a Chat App Using Azure Services
    1. Technical requirements
    2. Azure serverless services
      1. Azure SignalR Service
      2. Azure functions
      3. Azure blob storage
      4. Azure Cognitive Services
    3. Project overview
    4. Building the serverless backend
      1. Creating a SignalR service
      2. Creating a storage account
      3. Creating a Cognitive Service
      4. Creating functions
        1. Creating the Azure service for functions
        2. Creating a function to return the connection information for the SignalR service
        3. Creating a message library
        4. Creating a storage helper
        5. Creating a function for sending messages
        6. Using the Computer Vision API to scan for adult content
        7. Creating a scheduled job to clear photos from storage
      5. Deploying the functions to Azure
    5. Summary
  14. Building a Real-Time Chat Application
    1. Technical requirements
    2. Project overview
    3. Getting started
    4. Building the chat app
      1. Creating the chat service
      2. Initializing the app
        1. Creating a resolver
        2. Creating a Bootstrapper
      3. Creating a base ViewModel
      4. Creating the Mainview
        1. Creating MainViewModel
        2. Creating the MainView
          1. Replacing the MainPage
          2. Editing the XAML
          3. Fixing the code behind the view
        3. Setting the main view
      5. Creating the ChatView
        1. Creating the ChatViewModel
          1. Creating the class
          2. Adding the text property
          3. Receiving messages
          4. Creating the LocalSimpleTextMessage class
          5. Sending text messages
          6. Installing the Acr.UserDialogs plugin
          7. Installing the Media plugin
          8. Sending photos
        2. Creating the ChatView
          1. Creating Base64ToImageConverter
          2. Creating the skeleton ChatView
          3. Adding ResourceDictionary
          4. Adding ListView
          5. Adding templates
          6. Creating a template selector
          7. Adding the buttons and entry control
          8. Fixing the code behind
        3. Styling
          1. Styling with CSS
          2. Applying the style sheet
      6. Handling life cycle events
    5. Summary
  15. Creating an Augmented-Reality Game
    1. Technical requirements
    2. Essential theory
    3. An overview of the project
    4. Beginning the project
      1. Creating the project
        1. Updating the Xamarin.Forms NuGet packages
        2. Setting the Android target to 8.1
        3. Adding the camera permission to Android
        4. Adding Camera Usage Description for iOS
      2. Defining the user interface
        1. Creating the ARView control
        2. Modifying the MainPage
      3. Adding Urhosharp
        1. Installing the UrhoSharp NuGet package for iOS
        2. Installing the UrhoSharp.ARCore Nuget Package for Android
        3. Adding the Android life cycle events
        4. Defining the PlaneNode
        5. Adding custom renderers for the ARView control
          1. For iOS
          2. For Android
      4. Creating the game
        1. Adding the shared partial Game class
          1. CreateSubPlane
          2. UpdateSubPlane
          3. FindNodeByPlaneId
        2. Adding platform-specific partial classes
          1. Adding the iOS-specific partial class
          2. Adding the Android-specific partial class
      5. Writing the ARKit-specific code
        1. Defining the ARKitComponent
        2. Writing handlers for adding and updating anchors
          1. SetPositionAndRotation
          2. UpdateOrAddPlaneNode
          3. OnAddAnchor
          4. OnUpdateAnchors
        3. Writing a handler for removing anchors
          1. OnRemoveAnchors
        4. Initializing ARKit
      6. Writing ARCore-specific code
        1. Defining the ARCoreComponent
        2. SetPositionAndRotation
        3. Writing a handler for ARFrame updates
        4. Initializing ARCore
          1. OnConfigRequested
          2. InitializeAR
      7. Writing the game
        1. Adding a camera
        2. Configuring a renderer
        3. Adding lights
        4. Implementing the game startup
        5. Adding boxes
          1. AddBox()
          2. OnUpdate()
        6. Making boxes rotate
          1. Creating the rotate component
          2. Assigning the Rotator component
        7. Adding box hit-test
          1. Adding a death animation
          2. DetermineHit()
          3. OnTouchBegin()
          4. Wiring up input
      8. Updating statistics
        1. Defining a statistics class
        2. Sending updates via MessagingCenter
        3. Wiring up events
        4. Updating the GUI
        5. Subscribing to the updates in the MainForm
    5. Summary
  16. Hot Dog or Not Hot Dog Using Machine Learning
    1. Technical requirements
    2. Machine learning
      1. Azure Cognitive Services – Custom Vision
      2. CoreML
      3. TensorFlow
    3. Project overview
    4. Getting started
    5. Building the Hot Dog or Not Hot Dog application using machine learning
      1. Training a model
        1. Tagging images
        2. Training a model
        3. Exporting a model
      2. Building the app
        1. Classifying images with machine learning
          1. Using CoreML for image classification
          2. Using TensorFlow for image classification
        2. Creating a base ViewModel
        3. Initializing the app
          1. Creating a Resolver
          2. Creating a Bootstrapper
          3. Creating the iOS bootstrapper
          4. Creating the Android bootstrapper
        4. Building the first view
          1. Building the ViewModel
          2. Building the view
        5. Building the result view
          1. Building the ViewModel
          2. Building the view
    6. Summary
  17. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Xamarin.Forms Projects
  • Author(s): Johan Karlsson, Daniel Hindrikes
  • Release date: December 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781789537505