We previously defined the ItemSelected command in the HeadlinesViewModel class. It's now time to add code that will perform the navigation to the ArticleView by following these two steps:
- In the News project, expand the ViewModels folder and open HeadlinesViewModel.cs.
- Locate the ItemSelected property and add the following line marked in bold:
public ICommand ItemSelected =>
new Command(async (selectedItem) =>
{
var selectedArticle = selectedItem as Article;
var url = HttpUtility.UrlEncode(selectedArticle.Url);
await Navigation.NavigateTo($"articleview?url={url}");
});
We will define a route called articleview that takes a query-line parameter called url that points the URL of the article itself, and it will look something like this: articleview?url=www.mypage.com. Only the data passed after the url= argument must be UrlEncoded, meaning...