I am using MvvmCross in a Xamarin Android project. I have an MvxActivity with an MvxRecyclerView that I have assigned an element template in its layout file.
<MvxRecyclerView android:id="@+id/my_recycler_view" local:MvxItemTemplate="@layout/item_recycler_view" />
ViewModel is quite simple, it consists of only one property, which contains data for display in RecyclerView :
public class MainViewModel : MvxViewModel { private IEnumerable<ViewModelItem> _viewModelItems; public IEnumerable<ViewModelItem> ViewModelItems { get { return _viewModelItems; } set { SetProperty(ref _viewModelItems, value); } } }
Generally, I like to use the MvvmCross API as much as possible because of the implicit support for refactoring. Therefore, in my activity, I bind the MvxRecyclerView property as follows:
var recyclerView = View.FindViewById<MvxRecyclerView>(Resource.Id.my_recycler_view); var set = this.CreateBindingSet<MainView, MainViewModel>(); set.Bind(recyclerView) .For(v => v.ItemsSource) .To(vm => vm.ViewModelItems); set.Apply();
So far so good. Now the layout file for the element template basically just contains a TextView :
<LinearLayout> <TextView android:id="@+id/innerText" /> </LinearLayout>
And my ViewModelItem class looks like this:
public class ViewModelItem { public string Title { get; set; } }
Now my question is: how and where do I bind the TextView.Text property to the ViewModelItem.Title property using the free API?
I know that it’s quite easy to do without a free API by providing the MvxBind attribute in the element template’s layout file, but I would prefer a free API solution.