Mastering Xamarin UI Development - Second Edition

Book description

Learn how to build stunning, maintainable, cross-platform mobile application user interfaces using C# 7 with the power of both the Xamarin and Xamarin.Forms frameworks.

Key Features

  • Build effective native and cross-platform user interfaces using the Xamarin frameworks for iOS and Android, as well as Xamarin.Forms.
  • Maximize the testability, flexibility, and overall quality of your Xamarin mobile apps.
  • Step-by-Steps guide that is packed with real-world scenarios and solutions, to build professional grade mobile apps and games for the iOS and Android platforms, using C# 7.

Book Description

This book will provide you with the knowledge and practical skills that are required to develop real-world Xamarin and Xamarin.Forms applications. You'll learn how to create native Android app that will interact with the device camera and photo gallery, and then create a native iOS sliding tiles game. You will learn how to implement complex UI layouts and creating customizable control elements based on the platform, using XAML and C# 7 code to interact with control elements within your XAML ContentPages.

You'll learn how to add location-based features by to your apps by creating a LocationService class and using the Xam.Plugin.Geolocator cross-platform library, that will be used to obtain the current device location. Next, you'll learn how to work with and implement animations and visual effects within your UI using the PlatformEffects API, using C# code.

At the end of this book, you'll learn how to integrate Microsoft Azure App Services and use the Twitter APIs within your app. You will work with the Razor Templating Engine to build a book library HTML5 solution that will use a SQLite.net library to store, update, retrieve, and delete information within a local SQLite database. Finally, you will learn how to write unit tests using the NUnit and UITest frameworks.

What you will learn

  • Build native and cross-platform apps for both iOS and Android using the Xamarin and Xamarin.Forms platform using C# 7.
  • Implement and customize different user-interface layouts and Animations within your application and use the PlatFormEffects API to change appearance of control elements.
  • Understand the MVVM architectural pattern and how to implement this with your apps.
  • Build a NavigationService class to enable. navigation between your ViewModels as well as Implementing Data-Binding to control elements within your XAML pages and ViewModels.
  • Work with the Razor Templating Engine to create Models and Razor Pages that communicate with an SQLite database.
  • Build a LocationService class to incorporate location-based features within your cross-platform apps to display the user's current location by creating a custom cross-platform map control and handle location tracking updates.
  • Work with the Microsoft Azure App Services Platform and Implement Social networking features within your app using the Twitter API.
  • Unit Testing your Xamarin.Forms apps using the NUnit and UITest Frameworks

Who this book is for

This book is intended for readers who have experience using at least the C# 6.0 programming language and interested in learning how to create stunning native, and cross-platform user interfaces for the iOS and Android platforms using the Xamarin and Xamarin.Forms frameworks using C# 7.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Mastering Xamarin UI Development Second Edition
  3. Dedication
  4. www.PacktPub.com
    1. Why subscribe?
    2. PacktPub.com
  5. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Acknowledgments
  7. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Downloading the example code
      2. Download the color images
    4. Conventions used
    5. Get in touch
      1. Reviews
  8. Setting Up Visual Studio for Mac
    1. Downloading and installing Visual Studio for Mac
      1. Installing Visual Studio for Mac and Xamarin
    2. Exploring the Microsoft Visual Studio for Mac IDE
      1. Configuring and including additional .NET Runtimes
      2. Defining your Android and iOS SDK locations
    3. Understanding the Xamarin mobile platform
      1. Benefits of developing apps using the Xamarin mobile platform
      2. Developing native apps using the Xamarin approach
      3. Developing apps using the Xamarin.Forms approach
    4. Creating a Xamarin project for both iOS and Android
      1. Creating the user interface for our Planetary app using XAML
      2. Displaying a list of planet names using C#
      3. Launching the Planetary app using the iOS simulator
    5. Using and setting Breakpoints in your code
      1. Setting a Breakpoint in your Planetary App solution
      2. Using the Breakpoints Pad to view Breakpoints that have been set
      3. Creating conditional Breakpoints to perform an action
    6. Using the Visual Studio for Mac built-in debugger
      1. Overview of the Visual Studio for Mac debugger
      2. Using the debugger to step through your code
      3. Using the Immediate window to print code variable contents
    7. Summary
  9. Building a PhotoLibrary App Using Android
    1. Creating a native Android app using Visual Studio for Mac
      1. Adding the Xamarin Media Plugin NuGet package to our solution
      2. Creating the user interface for our PhotoLibrary app using XML
      3. Updating the Strings XML file to include our UI control values
      4. Creating the Styles XML file for our Photo Library app
    2. Creating and implementing the PhotoLibrary Activity class
      1. Updating the MainActivity class to call the PhotoLibrary Activity
    3. Implementing Material Design in the PhotoLibrary app
      1. Creating custom themes for the PhotoLibrary application
        1. Creating custom styles for the Photo Library application UI controls
        2. Applying the custom theme to the PhotoLibrary application
    4. Setting up camera and photo album permissions
      1. Interacting with the device camera and photo album
    5. Launching the Photo Library app using the Android emulator
    6. Summary
  10. Building a SlidingTiles Game Using Xamarin.iOS
    1. Creating a native iOS app using Visual Studio for Mac
    2. Creating the SlidingTiles user interface using Storyboards
      1. Adding a label to our ViewController in the Storyboard
      2. Adding a View to our View Controller in the Storyboard
      3. Adding a reset button to our View Controller in the Storyboard
      4. Adding the Shuffle Button to our View Controller in the Storyboard
      5. Adding the GameTile image to our SlidingTiles game
    3. Implementing the game logic for our SlidingTiles Game
      1. Creating and implementing the GameTile Interface class
      2. Creating and implementing the GameTile class
      3. Updating the ViewController class to implement our class methods
      4. Creating and implementing the CreateGameBoard method
      5. Creating and implementing the ResetGame_Clicked method
      6. Randomly shuffling our Game Tiles on the Game Board
      7. Implementing the StartNewGame Instance method
      8. Handling touch events in the Game Board user interface
    4. Working with and applying animations to your app
      1. Creating and implementing animations for the SlidingTiles game
    5. Launching the SlidingTiles game using the iOS simulator
    6. Summary
  11. Creating the TrackMyWalks Native App
    1. Creating the TrackMyWalks project solution
      1. Updating the NuGet packages within our solution
    2. Creating and implementing our data model
    3. Creating the WalksMainPage interface using XAML
    4. Implementing the WalksMainPage code using C#
    5. Creating the WalkEntryPage interface using XAML
    6. Implementing the WalkEntryPage code using C#
    7. Creating the WalkTrailInfoPage interface using XAML
    8. Implementing the WalkTrailInfoPage code using C#
      1. Integrating and implementing maps within your app
    9. Creating the WalkDistancePage interface using XAML
    10. Implementing the WalkDistancePage code using C#
    11. Updating the TrackMyWalks.iOS AppDelegate
    12. Updating the TrackMyWalks.Android MainActivity
    13. Creating the SplashPage interface using XAML
    14. Implementing the SplashPage code using C#
      1. Updating the App.xaml class to target various platforms
    15. Launching TrackMyWalks using the iOS simulator
    16. Summary
  12. MVVM and Data Binding
    1. Understanding the MVVM architectural pattern
    2. Creating and implementing the BaseViewModel
    3. Creating the WalksMainPageViewModel using C#
      1. Updating the WalksMainPage user interface using XAML
      2. Updating the WalksMainPage code-behind using C#
    4. Creating the WalkEntryPageViewModel using C#
      1. Updating the WalkEntryPage user interface using XAML
      2. Updating the WalkEntryPage code-behind using C#
    5. Creating the WalkTrailInfoPageViewModel using C#
      1. Updating the WalkTrailInfoPage user interface using XAML
      2. Updating the WalkTrailInfoPage code-behind using C#
    6. Creating the WalkDistancePageViewModel using C#
      1. Updating the WalkDistancePage user interface using XAML
      2. Updating the WalkDistancePage code-behind using C#
    7. Launching the TrackMyWalks app using the iOS simulator
    8. Summary
  13. Navigating Within the Mvvm Model
    1. Understanding the Xamarin.Forms Navigation API
    2. Differences between the Navigation and ViewModel approaches
    3. Creating and implementing the NavigationService interface
    4. Creating and implementing the NavigationService class
    5. Updating the BaseViewModel to use the navigation service
    6. Updating the WalksMainPageViewModel using C#
    7. Updating the WalksMainPage code-behind using C#
    8. Updating the WalkEntryPageViewModel using C#
    9. Updating the WalkEntryPage code-behind using C#
    10. Updating the WalkTrailInfoPageViewModel using C#
    11. Updating the WalkTrailInfoPage code-behind using C#
    12. Updating the WalkDistancePageViewModel using C#
    13. Updating the WalkDistancePage code-behind using C#
    14. Updating the SplashPage code-behind using C#
    15. Updating the App.xaml class to use the navigation service
    16. Summary
  14. Adding Location-based Features Within Your App
    1. Creating and using platform-specific services within your app
      1. Adding the plugin geolocator NuGet package to our solution
    2. Creating and implementing the ILocationService interface
    3. Creating and implementing the LocationService class
    4. Updating the WalkEntryPageViewModel using C#
    5. Updating the WalkDistancePageViewModel using C#
    6. Creating the CustomMapOverlay class using C#
    7. Updating the WalkDistancePage user interface using XAML
    8. Updating the WalkDistancePage code-behind using C#
    9. Creating and implementing the CustomMapRenderer (iOS)
    10. Creating and implementing the CustomMapRenderer (Android)
    11. Enabling background location updates and permissions
    12. Launching the TrackMyWalks app using the iOS simulator
    13. Summary
  15. Customizing the User Interface
    1. Customizing the DataTemplate in the WalksMainPage
    2. Applying padding and margins to XAML layouts
      1. Updating the WalksMainPage user interface using XAML
      2. Updating the WalkEntryPage user interface using XAML
      3. Updating the WalkTrailInfoPage user interface using XAML
    3. Creating and implementing Styles in your App
      1. Creating and implementing Global Styles using XAML
      2. Updating our WalksMainPage to use the Device Style
      3. Updating our WalkTrailInfoPage to use Explicit and Global Styles
      4. Updating our WalksEntryPage to use our Implicit Style
    4. Creating and using PlatformEffects in your app
      1. Creating and Implementing the ButtonShadowEffect (iOS)
      2. Creating and implementing the LabelShadowEffect (iOS)
      3. Creating and implementing the ButtonShadowEffect (Android)
      4. Creating and implementing the LabelShadowEffect (Android)
      5. Implementing the ButtonShadowEffect RoutingEffect class
      6. Implementing the LabelShadowEffect RoutingEffect class
      7. Updating the WalksMainPage to use the LabelShadowEffect
      8. Updating the WalkTrailInfoPage to use the LabelShadowEffect
      9. Updating the WalkTrailInfoPage to use the ButtonShadowEffect
    5. Creating and implementing ValueConverters in your app
      1. Updating the BaseViewModel class to include additional properties
      2. Updating the WalksMainPageViewModel to use our property
      3. Updating the WalksMainPage to use our ImageConverter class
      4. Updating the WalkEntryPage to use our ImageConverter class
      5. Updating the WalkTrailInfoPage to use our ImageConverter class
    6. Launching the TrackMyWalks app using the iOS simulator
    7. Summary
  16. Working with Animations in Xamarin.Forms
    1. Creating and using Simple Animations in Xamarin.Forms
      1. Updating the WalkEntryPage to use Simple Animations
      2. Updating the WalkTrailInfoPage to use Simple Animations
    2. Creating and using Easing Functions in Xamarin.Forms
      1. Updating the WalkTrailInfoPage to use Easing Functions
    3. Creating and implementing your own Custom Animations
      1. Updating our WalkTrailInfoPage to use Custom Animations
      2. Updating our WalksMainPage to use Custom Animations
    4. Creating and implementing Entrance Animations
      1. Updating the WalkTrailInfoPage to use Entrance Animations
      2. Updating our WalksMainPage to use Entrance Animations
      3. Updating our WalkEntryPage to use Entrance Animations
    5. Launching the TrackMyWalks app using the iOS simulator
    6. Summary
  17. Working with the Razor Templating Engine
    1. Understanding the Razor templating engine
    2. Building a BookLibrary app using the Razor templating engine
    3. Adding the SQLite-net NuGet package to our solution
      1. Creating and implementing the BookLibrary data model
      2. Creating and implementing the BookDatabase interface
      3. Creating and implementing the BookDatabase class
    4. Creating and implementing the BookLibraryListing page
    5. Creating and implementing the BookLibraryAddEdit page
    6. Updating the Book Library cascading style sheet (CSS)
    7. Updating the WebViewController class using C#
    8. Launching the BookLibrary app using the iOS simulator
    9. Summary
  18. Incorporating Microsoft Azure App Services
    1. Understanding the Microsoft Azure App services platform
    2. Setting up and configuring Microsoft Azure App services
    3. Adding the Newtonsoft.Json NuGet package to our solution
    4. Updating the WalkDataModel for our TrackMyWalks app
    5. Creating and implementing the RestWebService interface
    6. Creating and implementing the RestWebService class
    7. Updating the BaseViewModel class to include our RestWebService
    8. Updating the WalksMainPage code-behind using C#
      1. Updating the WalksMainPageViewModel using C#
    9. Updating the WalkEntryPage user interface using XAML
      1. Updating the WalkEntryPageViewModel using C#
    10. Launching the TrackMyWalks app using the iOS simulator
    11. Summary
  19. Making Our App Social Using the Twitter API
    1. Creating and registering the TrackMyWalks app with the Twitter Developer Portal
      1. Adding the Xamarin.Auth NuGet Package to our solution
    2. Creating and implementing the TwitterAuthDetails class
    3. Creating and implementing the TwitterWebService interface
    4. Creating and implementing the TwitterWebService class
    5. Creating and implementing the TwitterSignInPageViewModel using C#
    6. Creating and implementing the user interface for the TwitterSignInPage
    7. Creating and implementing the TwitterSignInPageRenderer (iOS)
    8. Updating the WalksMainPage code-behind using C#
    9. Updating the WalkDistancePage user unterface using XAML
    10. Registering the TwitterSignInPage within the App.xaml class
    11. Launching the TrackMyWalks app using the iOS simulator
    12. Summary
  20. Unit Testing Your Xamarin.Forms Apps
    1. Creating the Unit Testing project within the TrackMyWalks solution
      1. Adding the Moq NuGet package to the TrackMyWalks.UnitTests project
      2. Adding the TrackMyWalks project to the TrackMyWalks.UnitTests project
      3. Creating and implementing the WalksMainPageViewModelTest class
      4. Creating and implementing the WalksEntryPageViewModelTest class
    2. Running unit tests within the Visual Studio for Mac IDE
    3. Creating a UITest project within the TrackMyWalks solution
      1. Understanding the most commonly used Xamarin.UITest testing methods
      2. Creating and implementing the CreateNewTrailDetails class for iOS
    4. Updating the WalksMainPage code-behind using C#
    5. Adding the Xamarin.Test Cloud.Agent NuGet package
    6. Running UITests within the Visual Studio for Mac IDE
    7. Summary
  21. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Mastering Xamarin UI Development - Second Edition
  • Author(s): Steven F. Daniel
  • Release date: August 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788995511