As with all views, when using MVVM, we need to pass our view of ViewModel. Since we are using dependency injection in this project, we will pass it through the constructor and then assign it to the view's BindingContext. We will also make sure that we enable safe areas to avoid controls being partially hidden behind the iPhone X notch at the top:
- Open the MainView.xaml.cs file.
- Add a parameter called viewModel of the MainViewModel type in the constructor of the MainView class. The argument for this parameter will be injected by Autofac at runtime.
- Add a platform-specific statement that instructs the application to use safe areas on iOS. A safe area makes sure that the app does not use the space on the side of the notch at the top of the screen on an iPhone X.
- Assign the viewModel argument to the BindingContext property of the view.
The changes that need to be made have been marked in bold in the following code:
using...