The MainViewModel that we are about to create will hold a username that the user will enter into the UI. It will also contain a Command property called Start. This will be bound to a Button that the user will click after entering their username:
- In the ViewModel folder, create a class called MainViewModel.cs.
- Inherit the class from ViewModel.
- Make the class public.
- Add a property called Username of the string type.
- Add a property called Start of the ICommand type and implement it, as shown in the following code. The Start command will assign Username from the Username property and assign it to the static User property in the base ViewModel. Then, it will create a new instance of ChatView by using Resolver and pushing it onto the navigation stack.
MainViewModel should now look as follows:
using System.Windows.Input;
using Chat.Views;
using Xamarin.Forms;
namespace Chat.ViewModels
{
public class MainViewModel : ViewModel...