I am trying to get Xamarin Forms to display a list in a list. I have seen other people say that a ListView nested in a ListView is not supported. I tried to add a control to the ListView and bind the nested list to the control, but my application always crashes when I try to bind it.
I also found that some people suggest using grouping. DOES grouping works, however, the problems that I found with this, I can not use in the grouping section. Also, the grouping will not be updated in real time (this is a requirement).
For the end result, I would like to do something simple:
- ApartmentName1
- Address
- Manager Phone Number
- Tenant 1, phone number
- Tenant 2, phone number
- Tenant 3, phone number
- ApartmentName2
- Address
- Manager Phone Number
- Tenant 1, phone number
- Tenant 2, phone number
- Tenant 3, phone number
The following is an example of an object that I would like to display in my Xamarin Forms project.
public class Apartment { public string ApartmentName { get; set; } public string Address { get; set; } public string ManagerPhoneNumber { get; set; } public List<Tenant> Tenants { get; set; } } public class Tenant { public string FullName { get; set; } public string PhoneNumber { get; set; } public DateTime ContractExpireDate { get; set; } }
Here is the Haml I was trying to work with
<ContentView> <StackLayout> <ListView x:Name="apartmentListView" HasUnevenRows="True"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <ViewCell.View> <StackLayout VerticalOptions="StartAndExpand"> <StackLayout Orientation="Horizontal" BackgroundColor="Gray"> <Label HorizontalOptions="StartAndExpand" Text="{Binding ApartmentName}" /> <Label HorizontalOptions="End" Text="{Binding Address}" /> </StackLayout> <Label Text="{Binding ManagerPhoneNumber}" /> <control:TenantViewTemplate Tenants="{Binding Tenants}" /> </StackLayout> </ViewCell.View> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> </StackLayout> </ContentView>
I am only trying to show a list containing a list. I am open to any suggestions on how to do this using Xamarin forms.
source share