Retrieving the param from the previous ViewModel
In the PostDetailViewModel
, we need to get the param from the IMvxNavigationService
. Change the basic class of the PostDetailViewModel
like this:
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:
Create a new object to store the comments:
And update the Prepare
method to initialize the variables like this:
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.
Last updated