Hello,
If you want to show the data in the Listview, your Model need to change it like following structure. MyModel.cs
contains List<MyListModel> Assignments
, I add the Name property for testing. Name property could show in the CarouselView
If you add Label
in the StackLayout
. If you do not need Name property, you can remove it.
MyListModel.cs
contains properties(I add DisplayName
in the Listview's <TextCell>
) that you want to Show them in the Listview.
public class MyModel
{
public string Name { get; set; }
public List<MyListModel> Assignments { get; set; }
public MyModel()
{
}
}
public class MyListModel
{
public string DisplayName { get; set; }
}
Here is my test AssignmentsViewModel.cs
. I add <TextCell Text="{Binding DisplayName}" />
in <DataTemplate>
of <ListView.ItemTemplate>
. DisplayName
could appear normally.
public class AssignmentsViewModel
{
public ObservableCollection<MyModel> AssignmentsCalendar { get; set; }
public AssignmentsViewModel(INavigation navigation, ContentPage mainPage)
{
//Create a dataset to appear in the Listview
var Assignments = new List<MyListModel>();
Assignments.Add(new MyListModel() { DisplayName = "test1" });
Assignments.Add(new MyListModel() { DisplayName = "test2" });
//Set value to the AssignmentsCalendar
AssignmentsCalendar = new ObservableCollection<MyModel> { new MyModel() { Name="Cars1", Assignments = Assignments }, new MyModel() { Name = "Cars2", Assignments = Assignments } };
}
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.