I've made a sample App to test Xamarin.Forms ListView renderers because i've got some updating issues in a "production app" and i noticed something weird with bindings.
I'm using Xamarin.Forms 2.0, Xamarin.Android(Android 5+ Lollipops) and Xamarin.IOS (iOS 8+) and I followed this documentation
Here's what i've got:
- A NativeListView subclass of ListView
- An Android ListViewRenderer with his Adapter and a customCell.axml
- An iOS ListViewRenderer with his Source and customCell.cs
- A CellModel.cs which has only 2 properties (Title, Description)
- A simple ViewModel (inherits from ViewModelBase because i use MVVMLight) containing an ObservableCollection, and 3 commands (Add, Reset, Clear).
- A simple ContentPage with the NativeListView inside bound on the ViewModel collection property, and 3 buttons bound to the VM Commands.
Here's what happens:
- If I use a Xamarin.Forms ListView bounds to the viewmodel, it's working fine, the page/listview are updated according to the VM's datasource.
- If i use the NativeListView bounds to the viewmodel, and a renderer, both on iOS and Android, when I add / remove an item from the VM's datasource, it doesn't update at all. I never go in the Renderer OnElementPropertyChanged.
- If i use the NativeListView bounds to the viewmodel and a renderer, both on iOS and Android, when I set the VM's datasource property, it does update the ListView.
So in my opinion it's not working as expected. I shouldn't have to reset the VM's datasource property each time i want to add / remove an object.
Am i missing something ?
I've attached the sample project below if you want to see the code.
PS : In the example, they use an Items BindableProperty on the NativeListView, but the result was the same so i just removed it and used the build in ItemSource ListView property.