Phone Book 2.0

Using the Visual Studio integrated development environment and the C# programming language, we will develop a cross-platform mobile application for a phone book containing a list of contacts.

Start

  1. Launch the Visual Studio integrated development environment.

  2. Create a new project: Visual C# > Cross-Platform > Mobile App (Xamarin.Forms).

  3. Name the project: Phone Book 2.0.

Add additional packages to the project by installing Newtonsoft.Json from: Tools > NuGet Package Manager > Package Manager Console, by running the following command in the console:

PM> Install-Package Newtonsoft.Json -Version 13.0.1

Contact.cs

Add a new class Contact.cs containing the following code fragment:

public class Contact
{
        private Uri picture;

        public Uri Picture
        {
            get { return picture; }
            set { picture = value; }
        }

        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private string phone;

        public string Phone
        {
            get { return phone; }
            set { phone = value; }
        }

        public Contact(Uri picture, string name, string phone)
        {
            this.picture = picture;
            this.name = name;
            this.phone = phone;
        }
}

ViewModel.cs

Add a new class ViewModel.cs containing the following code fragment:

MainPage.xaml

The MainPage.xaml file contains the source code for the application's user interface design and is written in XAML. Copy (Ctrl+C) and paste (Ctrl+V) the fragment below into your application.

MainPage.xaml.cs

The MainPage.xaml.cs file contains the source code for the application's business logic and is written in C#. Copy (Ctrl+C) and paste (Ctrl+V) the fragment below into your application.

AddPage.xaml

Add a new page AddPage.xaml. Copy (Ctrl+C) and paste (Ctrl+V) the fragment below into your application.

AddPage.xaml.cs

Open the file AddPage.xaml.cs. Copy (Ctrl+C) and paste (Ctrl+V) the fragment below into your application.

Demo

Run the application from the menu: Debug > Start Debugging or by pressing the F5 key.

Fig. 2.64. Demonstration of the cross-platform mobile phone book application

Used images for user profiles

  1. Male: https://icons-for-free.com/business+costume+male+man+office+user+icon-1320196264882354682.png

  2. Female: https://icons-for-free.com/female+person+user+woman+young+icon-1320196266256009072.png

Last updated