How to update the data in listview in Xamarin.Forms?

First you add a new class as a ViewModel like:

public class RoomViewModel : BaseViewModel
   [here following code]

If you don’t have BaseViewModel try to download from nuget Refractored.MvvmHelpers. Then in your class define an observable collection like

  public ObservableCollection<RoomRecommandation> _roomSuggestionList = 
               new ObservableCollection<RoomRecommandation>();
  public ObservableCollection<RoomRecommandation> Recommendations
     get { return _roomSuggestionList; }

In your ContentPage add a listview like:

<ListView ItemsSource="{Binding Recommendations}">
       <Grid Padding="10" RowSpacing="10" ColumnSpacing="10">
           <RowDefinition Height="" />
           <ColumnDefinition Width="Auto" />
           <ColumnDefinition Width="" />
           <ColumnDefinition Width="Auto" />
         <controls:CircleImage Grid.Column="0" BorderColor="#DDD3CB" 
                               BorderThickness="3" WidthRequest="66"
                               Source="{Binding Image}" />
         <Label Grid.Column="1" Text="{Binding Description}" 
                               VerticalOptions="Start" />
         <Label Grid.Column="2" Text="{Binding Price, StringFormat='£{0}'"
                               FontSize="Small" VerticalOptions="Start" />

Then in your ContentPage code:

  RoomViewModel vm = null;
  public RoomPage ()
      InitializeComponent ();

  public void LoadData()
      if (vm == null)
          vm = new RoomViewModel();
          BindingContext = vm;

Happy coding!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.