The next step is to create the view that we will use when the app is running on a tablet or a desktop computer. Let's set this up:
- Create a new folder in the Weather project called Views.
- Create a new Content Page with XAML called MainView.
- Use Resolver in the constructor of the view to set BindingContext to MainViewModel, as shown in the following code:
public MainView ()
{
InitializeComponent ();
BindingContext = Resolver.Resolve<MainViewModel>();
}
To trigger the LoadData method in MainViewModel, call the LoadData method by overriding the OnAppearing method on the main thread. We need to make sure that the call is executed on the UI thread since it will interact with the user interface.
To do this, perform the following steps:
- In the Weather project, open the MainView.xaml.cs file.
- Create an override of the OnAppearing method.
- Add the code...