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

Using the XLabs CarouselView Control

$
0
0

I'm trying to make a simple image carousel but am unable to get anything to display. I have tested the DataTemplate with the Xlabs RepeaterView and the Xamarin ListView with the same ViewModel and bindings to confirm that those are correct. Here is the code:

            XLabs.Forms.Controls.CarouselView<Photo> carousel = new XLabs.Forms.Controls.CarouselView<Photo>
            {
                TemplateSelector = new TemplateSelector
                {
                    Templates = new DataTemplateCollection
                    {
                        new DataTemplateWrapper<Photo>{

                            IsDefault = true,
                            WrappedTemplate = new DataTemplate(()=>
                            {
                                var l = new StackLayout();
                                l.BackgroundColor = Color.FromHex("#f2f2f2"); // added a background color to see if a stacklayout would be displayed.  It isn't
                                Image image = new Image
                                {
                                    Aspect = Aspect.AspectFill,
                                    HorizontalOptions = LayoutOptions.FillAndExpand,
                                    VerticalOptions = LayoutOptions.FillAndExpand
                                };
                                image.SetBinding<Photo>(Image.SourceProperty, (ph) => ph.ImageSource);
                                l.Children.Add(image);
                                return l;
                            })

                        }
                    }
                }
            };

            carousel.SetBinding(XLabs.Forms.Controls.CarouselView<Photo>.ViewModelsProperty, "Photos");`

The difference between this and the Repeater/ListView controls appears to be the TemplateSelector and TemplateWrapper properties, so perhaps I'm doing something wrong there. There is a CarouselSample here in XAML: https://github.com/XLabs/Xamarin-Forms-Labs/tree/master/Samples/XLabs.Sample/Pages/Controls but I can't see anything that I'm missing off-hand.


Viewing all articles
Browse latest Browse all 75885

Trending Articles



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