Reputation: 969
How implement adapter in xamarin.forms (xaml) simple ? But all example is for andorid or iOS. Can writing example for xamarin.forms
Upvotes: 1
Views: 1180
Reputation: 3678
Adapters are part of the native Android UI framework for displaying data using the MVC pattern. In the world of Xamarin Forms, the best analogue is a ViewModel and the Model View ViewModel pattern (MVVM). In its simplest form, a ViewModel is any class that the view binds to by having an instance of that class assigned to the View's BindingContext. This is, by itself, enough to perform one-time binding where the values in that class' properties are read by the View when the View is created. If you want more advanced binding where updates to the underlying ViewModel are reflected in the View, you need to implement INotifyPropertyChanged and send notifications to the View. Also, rather than roll your own, I would recommend that you look into using an existing MVVM framework such as MvvmLight.
To acheieve what you are looking for, you would have a ViewModel expose a property that is of an IEnumerable or IList. You could then bind one of the repeating views such as ListView to this property and see the underlying data reflected in the view. By implementing INotifyPropertyChanged (or using a framework that does that for you), you can have new items added to the collections exposed by those properties appear in the UI.
Upvotes: 1