Some mobile apps have to display a list of information to users, so there's no wonder that the listview is a primary control seen in almost every app.
In this post, we will create listview and populate it using list object.
So let's get started.
Step 1: Right-click on your PCL project then Add > Class. Then name it EventsModel.
Step 2: Go to your EventsModel.cs and add the following properties,
Step 3: Right-click on your PCL project then Add > New Item > Content Page. Name it EventsListPage. Go to EventsListPage.xaml then add ListView.
Step 4: Create DataTemplate to bind between a data source and the cell. Using this approach, you could easily customize cell or create a completely new look and feel by extending the ViewCell. For more info, visit https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/templates/data-templates/creating
Step 5: Go to EventsListPage.xaml.cs then initialize and instantiate EventsModel object list.
Step 6: Add items to your list object
Step 7: Set your list object as your ListView's item source
Step 8: Go to EventsListPage.xaml once again and add ItemTapped event to your ListView. Go to EventsListPage.xaml.cs and under listViewEvent_ItemTapped event, add this:
Step 9: Build and deploy your app to your emulator or device.
And here’s what the app looks like when is running.
Here’s the VSTS GitHub repo of this demo.
That’s it! Try it yourself!
Until next time. Happy coding!
wow. nice blog! :D