Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Error when creating custom ItemsViewController in custom CollectionViewRenderer

$
0
0

Hi.
I tried create custom ItemsViewController, but I get an error when calling base.OnElementChanged(e):
System.InvalidCastException: Specified cast is not valid.
at Xamarin.Forms.Platform.iOS.SelectableItemsViewRenderer.get_SelectableItemsViewController () [0x00000] in D :\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\SelectableItemsViewRenderer.cs:9
at Xamarin.Forms.Platform.iOS.SelectableItemsViewRenderer.SetUpNewElement (Xamarin.Forms.ItemsView newElement) [0x00035] in D :\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\SelectableItemsViewRenderer.cs:44
at Xamarin.Forms.Platform.iOS.ItemsViewRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x0000c] in D :\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ItemsViewRenderer.cs:29

My code:

    public class CustomCollectionViewRenderer: CollectionViewRenderer
        {
            protected override void OnElementChanged(ElementChangedEventArgs<ItemsView> e)
            {
                base.OnElementChanged(e);
                if (Control == null)
                    return;
            }

            protected override ItemsViewController CreateController(ItemsView itemsView, ItemsViewLayout layout)
            {
                return new CustomCollectionViewController(itemsView, layout);
            }

            public class CustomCollectionViewController : ItemsViewController
            {
                public CustomCollectionViewController(ItemsView itemsView, ItemsViewLayout itemsViewLayout): base(itemsView, itemsViewLayout)
                {

                }       
            }
        }

what am I doing wrong?


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>