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

Creating the ItemViewModel

The ItemViewModel represents the to-do list item in a view that can be used to create new items and to edit existing items:

  1. In the ViewModels folder, create a class called ItemViewModel.
  2. Add the code as following:
using DoToo.Models;
using DoToo.Repositories;
using System;
using System.Windows.Input;
using Xamarin.Forms;

namespace DoToo.ViewModels
{
public
class ItemViewModel : ViewModel
{
private TodoItemRepository repository;

public ItemViewModel(TodoItemRepository repository)
{
this.repository = repository;
}

}
}

The pattern is the same as for the previous two ViewModels:

  • We use dependency injection to pass the TodoItemRepository into the ViewModel
  • We use inheritance from the ViewModel base class to add the common features defined by the base class