Exemplo n.º 1
0
        public override void UpdateAdapter()
        {
            // By default the CollectionViewAdapter creates the items at whatever size the template calls for
            // But for the Carousel, we want it to create the items to fit the width/height of the viewport
            // So we give it an alternate delegate for creating the views

            var oldItemViewAdapter = ItemsViewAdapter;

            UnsubscribeCollectionItemsSourceChanged(oldItemViewAdapter);
            if (oldItemViewAdapter != null)
            {
                ItemsView.SetValueFromRenderer(CarouselView.PositionProperty, 0);
                ItemsView.SetValueFromRenderer(CarouselView.CurrentItemProperty, null);
            }

            ItemsViewAdapter = CreateAdapter();

            _gotoPosition = -1;

            SwapAdapter(ItemsViewAdapter, false);

            UpdateInitialPosition();

            if (ItemsViewAdapter.ItemsSource is ObservableItemsSource observableItemsSource)
            {
                observableItemsSource.CollectionItemsSourceChanged += CollectionItemsSourceChanged;
            }

            oldItemViewAdapter?.Dispose();
        }
Exemplo n.º 2
0
        public override void UpdateAdapter()
        {
            // By default the CollectionViewAdapter creates the items at whatever size the template calls for
            // But for the Carousel, we want it to create the items to fit the width/height of the viewport
            // So we give it an alternate delegate for creating the views

            var oldItemViewAdapter = ItemsViewAdapter;

            if (oldItemViewAdapter != null)
            {
                UnsubscribeCollectionItemsSourceChanged(oldItemViewAdapter);
                ItemsView.SetValueFromRenderer(CarouselView.PositionProperty, 0);
                ItemsView.SetValueFromRenderer(CarouselView.CurrentItemProperty, null);
            }

            _gotoPosition = -1;

            base.UpdateAdapter();

            UpdateInitialPosition();

            SubscribeCollectionItemsSourceChanged(ItemsViewAdapter);
        }