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

Carousel

$
0
0

So I have posted on this topic before and only had a reply of "works for me". However, 2 months into Xamarin development this still does not work for me even with a simple example. I am only coding to Android platform for now.

Make a listview that has 12 items in it. Then the ItemSelected event goes like this:

storyList.ItemSelected += (sender, e) =>
            {
                if (e.SelectedItem == null) return;
                var index = data.IndexOf((TopStoryCard)e.SelectedItem);
                var id = ((TopStoryCard)e.SelectedItem).id;
                Navigation.PushAsync(new StoryCarousel(index));
                list.SelectedItem = null;
            };

Which goes to a simple carousel page:

public class StoryCarousel : CarouselPage
    {
        public StoryCarousel(int index)
        {
            Children.Add(new ContentPage { Content = new BoxView { Color = new Color(1, 0, 0) }, Title = "Page 1" });
            Children.Add(new ContentPage { Content = new BoxView { Color = new Color(0, 1, 0) }, Title = "Page 2" });
            Children.Add(new ContentPage { Content = new BoxView { Color = new Color(0, 0, 1) }, Title = "Page 3" });
            Children.Add(new ContentPage { Content = new BoxView { Color = new Color(1, 0, 0) }, Title = "Page 4" });
            Children.Add(new ContentPage { Content = new BoxView { Color = new Color(0, 1, 0) }, Title = "Page 5" });
            Children.Add(new ContentPage { Content = new BoxView { Color = new Color(0, 0, 1) }, Title = "Page 6" });
            Children.Add(new ContentPage { Content = new BoxView { Color = new Color(1, 0, 0) }, Title = "Page 7" });
            Children.Add(new ContentPage { Content = new BoxView { Color = new Color(0, 1, 0) }, Title = "Page 8" });
            Children.Add(new ContentPage { Content = new BoxView { Color = new Color(0, 0, 1) }, Title = "Page 9" });
            Children.Add(new ContentPage { Content = new BoxView { Color = new Color(1, 0, 0) }, Title = "Page 10" });
            Children.Add(new ContentPage { Content = new BoxView { Color = new Color(0, 1, 0) }, Title = "Page 11" });
            Children.Add(new ContentPage { Content = new BoxView { Color = new Color(0, 0, 1) }, Title = "Page 12" });

            this.SelectedItem = Children[index];
        }
    }

If i select the first item in the listview i get a display of the first child and can swipe through all the children just fine. If i select 2nd or 3rd index or pick an index other than the first item , it goes to a blank screen. Am i doing something wrong?


Viewing all articles
Browse latest Browse all 58056

Trending Articles



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