In the PostDetailViewModel, we need to get the param from the IMvxNavigationService. Change the basic class of the PostDetailViewModel like this:
publicclassPostDetailViewModel:MvxViewModel
Now it has a generic type constraint to receive the param. To do this, we need to update the Prepare override method, which is the right place to receive the param that is passed by the previous ViewModel. Add a private variable to store the post id:
And update the Prepare method to initialize the variables like this:
publicoverridevoidPrepare(Postpost){ // This is the first method to be called after constructionCommentList=newMvxObservableCollection<Comment>();_postId=post.Id;}
After that, we can use the _postId variable in the Initialize method to load the data from the APIs, as shown below:
Here is the result of the Android project:
For the UWP project:
Let us get deep into the IMvxNavigationService in the next section.