In this chapter, we will create a to-do list app and, in doing so, explore all the bits and pieces of what makes up an app. We will look at creating pages, adding content to pages, navigating between pages, and creating a stunning layout. Well, stunning might be a bit of a stretch, but we will be sure to design the app so that you can tweak it to your needs once it is complete!
The following topics will be covered in this chapter:
- Setting up the project
- Persisting data locally on a device
- Using the repository pattern
- What MVVM is and why it's a great fit for Xamarin.Forms
- Using Xamarin.Forms pages (as views) and navigating between them
- Using Xamarin.Forms controls in XAML
- Using data binding
- Using styling in Xamarin.Forms
To complete this project, you need to have Visual Studio installed to your Macintosh (Mac) or PC, as well as the Xamarin components. Refer to Chapter 1, Introduction to Xamarin, for more details on how to set up your environment.
An overview of the project
Everyone needs a way of keeping track of things. To kick-start our Xamarin.Forms development learning curve, we've decided that a to-do list app is the best way to get started and to help you keep track of things. A simple, classic win-win scenario.
We will start by creating a project and defining a repository to store the items of a to-do list. We will render these items in list form and allow the user to edit them using a detailed user interface. We will also look at how to store the to-do list items locally on a device through SQLite.NET so that they don't get lost when we exit the app.
The build time for this project is about 2 hours.
Beginning the project
It's time to start coding! Before starting, however, make sure you have your development environment set up as described in Chapter 1, Introduction to Xamarin.
This chapter will be a classic File | New | Project chapter, guiding you step by step through the process of creating your first to-do list app. There will be no downloads required whatsoever.
Setting up the project
A Xamarin app can essentially be created by using one of two code-sharing strategies:
- As a shared project
- The .NET Standard library
The first choice, a shared project, creates a project that is essentially a linked copy of each file in it. The files exist in one common place and are linked in at build time. This means that we cannot determine the runtime when writing the code and we can only access the APIs that are available on each target platform. It does allow us to use conditional compilations, which can be useful in certain circumstances, but can also be confusing to someone who...
You should now have a good grasp of all the steps involved in creating a Xamarin.Forms app from scratch. We learned about the project structure and the important files in a newly created project. We talked about dependency injection using Autofac and learned the basics of MVVM by creating all the views and the ViewModel classes needed. We also covered data storage in SQLite to persist data on our device in a fast and secure way. Using the knowledge gained from this chapter, you should now be able to create the backbone of any app you like.
The next chapter will focus on creating a richer user experience by creating a match-making application that displays images that you can pan around the screen. We will take a closer look at XAML and how to create custom controls.