Create new viewmodel for each group/item in an MvxExpandableListView

Radu_RZMRadu_RZM ROMember ✭✭
edited November 8 in Xamarin.Android

Hello, I am trying to create a simple MvxExpandableListView having a viewmodel assigned for every group/item that it contains. My code is the following:

The layout:
<?xml version="1.0" encoding="utf-8"?> <Mvx.MvxExpandableListView android:id="@+id/TripsExpandableListView" android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="match_parent" android:groupIndicator="@null" android:childDivider="@android:color/transparent" local:MvxBind="ItemsSource Trips" local:MvxItemTemplate="@layout/mytrips_listitem" local:MvxGroupItemTemplate="@layout/mytrips_listheader"/>

The code inside the viewmodel that contains the MvxExpandableListView:

private List<List<TripViewModel>> trips; public List<List<TripViewModel>> Trips { get { return trips; } set { trips = value; RaisePropertyChanged(() => Trips); } } public override void Prepare(Parameter parameter) { Trips = new List<TripViewModel>(); for (int i = 0; i < SharedResources.Trips.Count; i++) { var trip = SharedResources.Trips[i]; Trips.Add(new TripViewModel(trip.Distance.ToString(), trip.StopsNumber.ToString())); } }

In the application, the groups(headers) of the list are correctly drawn. However, when I try to expand the group, the application crashes. My thought is that the problem is being caused by the Trips list - I should have a List of viewmodels inside another list.
How can I fix this?

Tagged:
Sign In or Register to comment.