The INavigation interface is simple, and we will overshoot the target a little bit. We are really only interested in the NavigateTo method, but we will add the PushModal() and PopModal() methods since it is likely that you will use them if you continue extending the app.
Adding the navigation interface is simple, as the following steps illustrate:
- In the News project, expand the ViewModels folder and add a new file called INavigate.cs.
- Add the following code to the file:
using System.Threading.Tasks;
using Xamarin.Forms;
namespace News.ViewModels
{
public interface INavigate
{
Task NavigateTo(string route);
Task PushModal(Page page);
Task PopModal();
}
}
The NavigateTo() method declaration takes the route we want to navigate to. This is the method that we will be calling. The PushModal() method adds a new page on top of the navigation stack as a modal page, forcing the user only to interact with this specific page. The PopModal...