Creating and implementing the TwitterSignInPageViewModel using C#

In this section, we'll take a look at how to create the TwitterSignInPageViewModel class so that it can communicate with our TwitterSignInPage, as well as any data bindings associated with the ContentPage that will be used by the ViewModel. We will create and implement the underlying C# code for our ViewModel, which will be used by our TwitterSignInPage code-behind file so that it can navigate within our NavigationStack.

Let's start by creating the TwitterSignInPageViewModel for our TrackMyWalks app by performing the following steps:

  1. Ensure that the TrackMyWalks solution is open within the Visual Studio for Mac IDE.
  2. Next, right-click on the ViewModels folder, and choose Add | New File... from the pop-up menu, as you did in the section entitled Creating the WalksMainPageViewModel using C# within Chapter 5, MVVM and Data Binding.
  3. Then, ensure that the TwitterSignInPageViewModel.cs file, which is located within the ViewModels folder, is displayed within the code editor, and enter the following code snippet:
    //
// TwitterSignInPageViewModel.cs
// The ViewModel for our TwitterSignInPage ContentPage
//
// Created by Steven F. Daniel on 10/08/2018.
// Copyright © 2018 GENIESOFT STUDIOS. All rights reserved.
//
using System.Threading.Tasks;
using TrackMyWalks.Services;

namespace TrackMyWalks.ViewModels
{
public class TwitterSignInPageViewModel : BaseViewModel
{
public TwitterSignInPageViewModel(INavigationService navService) :
base(navService)
{
}
// Instance method to initialise the TwitterSignInPageViewModel
public override async Task Init()
{
await Task.Factory.StartNew(() =>
{
});
}
}
}

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

  1. We started by including references to the System.Threading.Tasks namespace so that we can access the classes that are defined within this namespace. We have also included a reference to the TrackMyWalks.Services namespace so that we can access our Navigation object, which will enable us to navigate within the NavigationStack.
  2. Next, we made sure that our TwitterSignInPageViewModel inherits from our BaseViewModel class and created the Init instance method that we defined within our BaseViewModel so that it can initialize our TwitterSignInPageViewModel.
..................Content has been hidden....................

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