Command with the parameter

Now come back to the PostListViewModel. Inject the instance of the IMvxNavigationService in the constructor, as shown below:

private readonly IPostService _postService;
private readonly IMvxNavigationService _navigationService;
public PostListViewModel(IPostService postService, IMvxNavigationService navigationService)
_postService = postService;
_navigationService = navigationService;

Add a new command called ShowPostDetailAsyncCommand in the PostListViewModel to respond the item click event, as shown below:

#region ShowPostDetailAsyncCommand;
private IMvxAsyncCommand<Post> _showPostDetailAsyncCommand;
public IMvxAsyncCommand<Post> ShowPostDetailAsyncCommand
if (_showPostDetailAsyncCommand != null)
return _showPostDetailAsyncCommand;
_showPostDetailAsyncCommand = new MvxAsyncCommand<Post>(async(post) => await ShowPostDetailAAsync(post));
return _showPostDetailAsyncCommand;
private async Task ShowPostDetailAsync(Post post)
// Implement your logic here.
await _navigationService.Navigate<PostDetailViewModel, Post>(post);

You can use the code snippet mvxcmdap to generate an async command. This command is an async command with a generic type Post as its param. When the user clicks the post item, I can get the current post id and pass it into the command.

For the MvvmCrossDemo.Droid project, update the data-binding in the PostListView.axml like this:

local:MvxBind="ItemsSource PostList; ItemClick ShowPostDetailAsyncCommand"
local:MvxItemTemplate="@layout/post_item" />

Now the ListView is able to respond the ItemClick event and pass the context (the current Post) to the ShowPostDetailAsyncCommand.

For the MvvmCrossDemo.iOS project, it is a little complicated. We need to create a new class called PostListTableSource that inherits from MvxTableViewSource to replace the default MvxStandardTableViewSource, then override the RowSelected method to response the item click event:

public class PostListTableSource : MvxTableViewSource
private static readonly NSString PostCellIdentifier = new NSString("PostCell");
public PostListTableSource(UITableView tableView) : base(tableView)
protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item)
var cell = TableView.DequeueReusableCell(PostCellIdentifier, indexPath);
cell.TextLabel.Text = ((WrapperPostViewModel)item).Post.Title;
cell.DetailTextLabel.Text = ((WrapperPostViewModel)item).Post.Body;
return cell;
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
base.RowSelected(tableView, indexPath);
var item = this.SelectedItem;

Then update the PostListView class like this:

public partial class PostListView : MvxTableViewController<PostListViewModel>
private PostListTableSource _source;
public PostListView (IntPtr handle) : base (handle)
public override void ViewDidLoad()
_source = new PostListTableSource(TableView);
TableView.Source = _source;
var set = this.CreateBindingSet<PostListView, PostListViewModel>();
set.Bind(_source).To(vm => vm.PostList);

For the MvvmCrossDemo.Uwp project, we need to install Behaviors package first from the NuGet Package Manager. Or you can input the command below in the Package Manager Console:

Install-Package Microsoft.Xaml.Behaviors.Uwp.Managed

We use the behaviour to support event command binding. Update the codes of the PostListView.xaml, as shown below:

Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
<ListView ItemsSource="{Binding PostList}">
<StackPanel HorizontalAlignment="Stretch">
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding ShowPostDetailAsyncCommand}"></core:InvokeCommandAction>
<TextBlock Text="{Binding Post.Title}" Style="{StaticResource TitleTextBlockStyle}"></TextBlock>
<TextBlock Text="{Binding Post.Body}"></TextBlock>

You can also use some other InvokeCommandAction to bind the command of the ViewModel, for example, you can set the IsItemClickEnabled property of the ListView as True and bind the command to the ItemClick event. There is not only one approach to achieve the goal, so just select the one you like. Make sure you are clear about the DataContext of your current controls to avoid some unexpected binding errors.