Xamarin.Forms Projects
上QQ阅读APP看书,第一时间看更新

Defining a to-do list item

We will start off by creating a TodoItem class, which will represent a single item in the list. This will be a simple Plain Old CLR Object (POCO) class, where CLR stands from Common Language Runtime. In other words, this will be a .NET class without any dependencies on third-party assemblies. To create the class, follow the steps:

  1. In the .NET Standard library project, create a folder called Models.
  2. Add a class called TodoItem.cs in that folder and enter the following code:
public class TodoItem
{
public int Id { get; set; }
public string Title { get; set; }
public bool Completed { get; set; }
public DateTime Due { get; set; }
}

The code is pretty self-explanatory; it's a simple Plain Old CLR Object (POCO) class that only contains properties and no logic. We have a Title that describes what we want to be done, a flag (Completed) that determines if the to-do list item is done, a Due date when we expect it to be done, and a unique id that we need later on for the database.