I'm implementing CollectionView as a StaggeredGridLayout and write a custom renderer for it on android as:
[assembly: ExportRenderer(typeof(CollectionView), typeof(CustomCollectionViewRenderer))]
namespace App.Droid
{
public class CustomCollectionViewRenderer : CollectionViewRenderer
{
public CustomCollectionViewRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<ItemsView> elementChangedEvent) { base.OnElementChanged(elementChangedEvent); if (elementChangedEvent.NewElement != null) { StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.Vertical); SetLayoutManager(manager); } } }
}
It's working fine at the start of the application when initialized, but when i try to update or add more items, the item source of collectionview does not accept any data and becomes empty. It only populate the data template of collectionview at initialization but not after updating.
At initialization :
After updating item source:
- I have tried by binding it to viewModel and also by directly setting its item source