View Model Items on ListView Xamarin Forms

Hey today I'll show you how to implement the MVVM pattern to update, add and remove data in a listview on Xamarin Forms.

Here the root project files



  • User.cs : This file contains our user model data in this case Name and Age.
  • UserVM.cs : This file contains all the logic to bind data between view and root model also implements INotifyPropertyChanged pattern.
  • EditUserPage.cs : This is the page to edit user info have two entries and on button to save data.
  • MainPage.cs : This page contains the main listview and a button to add a new user to the listview data we use an ObservableCollection that allow auto-refresh listview data when you modify the datasource, also I implement the listview ContextActions to allow user to modify the listview items with two options edit and delete(iOS swipe left and Android/WP Long click on cell).
Now we have the code for each file:


Here the result:





If you want to have access to full example go to this link https://github.com/AlejandroRuiz/XamarinFormsViewModel happy code also if you have doubts plea let me know via comments

Comentarios

  1. Hi Author just now i found your blog its really awesome. Keep this work. It will more helpful for xamarin app developers.
    Hire affordable Xamarin Developer

    ResponderEliminar

Publicar un comentario

Entradas populares de este blog

Xamarin Month: Fall in Love with Xamarin.Forms Shell

ASP.NET Core Identity with Cosmos DB (MongoDB) Part2: ASP.NET Core Code

C# Interface Ejemplo Sencillo