I am using MvvmCross in my Xamarin Android project. I have an MvxActivity
with an MvxRecyclerView
, that I have assigned an item template in its layout file.
<MvxRecyclerView
android:id="@+id/my_recycler_view"
local:MvxItemTemplate="@layout/item_recycler_view" />
The ViewModel is quite simple, it consists just of one property that holds the data to display in the 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 fluent API as much as possible because of the implicit refactoring support.
So in my activity, I am binding a property of the MvxRecyclerView
like this:
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 item 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; }
}
My question now is, how and where do I bind the TextView.Text
property to the ViewModelItem.Title
property using the fluent API?
I know it is quite easy to do without the fluent API by supplying an MvxBind
attribute in the item template layout file, but I would really prefer a fluent API solution.
ViewHolder
else any binding to ItemClick will have no affect. Example in this stackoverflow answer. – Harte