Updating the WalkEntryPageViewModel using C#

Now that we have updated our WalksMainPage code-behind file so that it can reference our NavigationService class, thereby enabling it to navigate to our ViewModels within our navigation stack, we can proceed and start updating the WalksEntryPageViewModel class so that it can use our navigation service.

Let's take a look at how we can achieve this by following these steps:

  1. Ensure that the WalkEntryPageViewModel.cs file is displayed within the code editor and enter in the following highlighted code sections within the code snippet:
     //
// WalkEntryPageViewModel.cs
// The ViewModel for our WalkEntryPage ContentPage
//
// Created by Steven F. Daniel on 5/06/2018.
// Copyright © 2018 GENIESOFT STUDIOS. All rights reserved.
//
using System;
using System.Threading.Tasks;
using TrackMyWalks.Models;
using TrackMyWalks.Services;

namespace TrackMyWalks.ViewModels
{
public class WalkEntryPageViewModel : BaseViewModel
{
public WalkEntryPageViewModel(INavigationService navService) : base(navService)
{
// Update the title if we are creating a new Walk Entry
if (App.SelectedItem == null)
{
PageTitle = "Adding Trail Details";
App.SelectedItem = new WalkDataModel();

// Set the default values when creating a new Trail
Title = "New Trail Entry";
Difficulty = "Easy";
Distance = 1.0;
}
else
{
// Otherwise, we must be editing an existing entry
PageTitle = "Editing Trail Details";
}
}
...
...
}
}

Now, let's start by taking a look at what we covered in the preceding code snippet:

  1. We started by including a reference to the TrackMyWalks.Services namespace so that we can access the classes and instance methods that are defined within the namespace.
  2. Finally, we modified the WalkEntryPageViewModel class constructor to include a parameter called navService that references our INavigationService interface. Since our ViewModel inherits from the BaseViewModel class, we have to honor this agreement.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.80.3