I cannot bind ItemClick from MvxRecyclerView (or its adapter) to a command on my ViewModel using the Fluent API. It works if I put both ItemsSource and ItemClick in XML, so I'm not interested in such a solution.
I used this post as a great landmark ( How to use the free MvvmCross API to bind the TextView of the RecyclerView to the ViewModel property on Android? ) And it all works, except that I cannot bind ItemClick to the MvxRecyclerView (or adapter) to the MainViewModel command , which will lead me to the next snippet (ItemsSource works like a charm, but its property, not the command!).
For brevity, I will not copy the code from the original message ( How to use the free MvvmCross API to bind the TextView of the RecyclerView element to the ViewModel property on Android? ), Suppose that the MainViewModel from this post has been expanded using the ShowItemCommand command as such:
public class MainViewModel : MvxViewModel { private IEnumerable<ViewModelItem> _viewModelItems; public IEnumerable<ViewModelItem> ViewModelItems { get { return _viewModelItems; } set { SetProperty(ref _viewModelItems, value); } } public MvxCommand<ViewModelItem> ShowItemCommand { get { return new MvxCommand<ViewModelItem>(selectedItem => { ShowViewModel<ViewModelItem> (new { itemId = selectedItem.Id }); }); } } }
and everything else was implemented in accordance with the link provided.
So now, in addition to the ItemsSource, I want to connect the ItemClick to the MvxRecyclerView (or adapter) to the command. The reason they are interchangeable is because MvxRecyclerView simply passes these commands to the adapter.
Apparently this should work ... but it is not:
adapter.ItemClick = ViewModel.ShowItemCommand;
This also does not work:
set.Bind(recyclerView).For(v => v.ItemClick).To(vm => vm.ShowItemCommand);
source share