Write Carousel View DataTemplate in C#

Hi

I'm attempting to implement the new Carousel View control in a Xamarin Forms project. Could someone please give some advice or point me in the right direction on how to write a DataTemplate for the Carousel View in C#. All examples use XAML. Any help will be greatly appreciated.

Best Answers

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I think you can use the same method you use for listview datatemplate, with a ViewCell

  • WendelFabianChinsamyWendelFabianChinsamy USMember ✭✭
    edited July 2016

    @AlessandroCaliaro I've actually tried that. Returns the following error System.InvalidOperationException: DataTemplate returned non-view content: 'WhiteRiverXamarin.Templates.CarouselViewCell'.

    Here is the DataTemplate:

    public class CarouselViewCell : ViewCell
    {
        public CarouselViewCell()
        {
            var image = new Image
             {
                  Aspect = Aspect.AspectFill,
                  HorizontalOptions = LayoutOptions.Center,
                  VerticalOptions = LayoutOptions.Center
               };
    
                image.SetBinding(Image.SourceProperty, "ImageBase64");
    
                View = image;
        }
    }
    

    Here is the initializing code:

    var carousel = new CarouselView
    {
                    VerticalOptions = LayoutOptions.FillAndExpand,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    ItemTemplate = new DataTemplate(typeof(CarouselViewCell)),
                    ItemsSource = new List<CarouselModel>() // Left out for brevity
    };
    
  • AdamMeaneyAdamMeaney USMember ✭✭✭✭✭

    It sounds like it wants the type to be a view, not a cell. Have you tried that?

  • WendelFabianChinsamyWendelFabianChinsamy USMember ✭✭
    edited July 2016

    @AdamMeaney I've changed my DataTemplate to extend View. I don't get the System.InvalidOperationException thrown anymore. I do however get an empty carousel. I've tried just returning the image for the carousel from the datatemplate like so:

    var carousel = new CarouselView
    {
        VerticalOptions = LayoutOptions.FillAndExpand,
        HorizontalOptions = LayoutOptions.FillAndExpand,
        ItemTemplate = new DataTemplate(() => 
        {
            var image = new Image
            {
                 Aspect = Aspect.AspectFill,
                 HorizontalOptions = LayoutOptions.Center,
                 VerticalOptions = LayoutOptions.Center
             };
    
              image.SetBinding(Image.SourceProperty, "ImageBase64");
    
              ItemImage.BindingContextChanged += (sender, e) =>
                {
                    dynamic x = BindingContext;
    
                    if (x != null)
                    {
                        try
                        {
                            byte[] imageByteArray;
    
                            if (x.ImageBase64 != null && x.ImageBase64 != "")
                            {
                                imageByteArray = Convert.FromBase64String(x.ImageBase64);
                                ItemImage.Source = ImageSource.FromStream(() => new MemoryStream(imageByteArray));
                            }
                            else
                            {
                                ItemImage.Source = ImageSource.FromStream(() => new MemoryStream(Convert.FromBase64String(NoImageBase64)));
                            }
                        }
                        catch (Exception ex) { }
                    }
                };
          return image;
        },
    ItemsSource = new List<CarouselModel>
    {
        new CarouselModel { ImageBase64 = "iVBORw0KGgoAAAANSUhEUgAAAlgAAAJYCAMAAACJuGjuAAABO1BMVEUAAACtra2qqqqqqqqrq6uqqqqqqqqqqqqqqqqqqqqqqqqrq6uqqqqqqqqsrKyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpqamqqqqqqqqqqqqqqqqqqqqqqqqrq6uqqqqqqqqqqqr///+qqqpGRkb9/f2vr6/4+Pi/v7/29vbz8/P7+/vo6Oja2trKysq8vLzw8PBKSkrNzc1RUVHExMS5ubmzs7PHx8fPz893d3fu7u7q6uqsrKzl5eXf39/s7Ozh4eHj4+OFhYVOTk7S0tKxsbHe3t63t7dycnJVVVX6+vqUlJRqampaWlq1tbVcXFyKioqQkJBjY2NfX1/W1taBgYHBwcGioqKenp7U1NSlpaV8fHzR0dFtbW1nZ2eZmZmhoaH0C0k9AAAAKnRSTlMABf3vHF7308Roywq8oA/ndeSBbvPbmVelUCSSOUU/FbTrS+B8iDOsLSDYJimQAAArJklEQVR42uzd7U7iQBQG4FIsRURBECwiuKCu2pOW8k0MXwH5ShATf/hrY2LC/V/Dkt3shimlgECB9n2u4WTOmXemUw4AAAAAAAAAAAAAAAAAAAAAAGDCdfSYiAnBUPz0we/3iZGAe4KnCd49EYiIPr//4TQeCgqxxOORiwMwK6fry2Bc8oopWlFK9Erx4OU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8oFAifZBDby0v45fLIhqr95mv78/oKNJLL8V7lHoPA5gk3JSu95+FCrWBBL1R6Gzz1FxqYinwtcVW7zJRYPw4yu0lMbo/p9zfRyuq+PGmpP6cKMcCnG+Y4utXuSj+ANJp1qu6n+aAzHj/Wn/m3t5rfK3zX056t223+qP46HjR9qs13tTGCeEPl8wnqVu52GpCQcJSmFOCbGG45DUhmOkJFCrIF6y04oLwr4QIKYD3HmgjftFvevkvgAyav9ImMqj9s5v7gqY1uEzNXFOUMq39grpiQxDVulRSlVZHOxH30535fEICx3Jkr75yxS+d3eZe5CipbDeLdwOSpd5C75l6J5O4Xcfv4wHkkIMEVIROKH+f1cgTkfrRQ4vS4ehVIHeemqFBfFTDL4WxgAwn++khlRjJeupPxBKnRUvD7laR8REREREREREREREREREREREf3xC1eycnIxKPp/AAAAAElFTkSuQmCC" }
    }
    };
    
  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    Image.SourceProperty should be an image present in your resources...
    Try to add a label instead of a Image (just to see if CarouselView and Binding works correctly)

  • WendelFabianChinsamyWendelFabianChinsamy USMember ✭✭
    edited July 2016

    @AlessandroCaliaro I've tried it with a label and it works great. I was also successful using converting an image from base64:

    ItemTemplate = new DataTemplate(() =>
                    {
                        var image = new Image
                        {
                            Aspect = Aspect.AspectFill,
                            HorizontalOptions = LayoutOptions.Center,
                            VerticalOptions = LayoutOptions.Center,
                            Source = ImageSource.FromStream(() => new MemoryStream(Convert.FromBase64String("base64stringgoeshere")))
                        };
    
                        return image;
                    })
    

    However i need to bind the carousel through from data received from a call to a service. Will this not be possible with the carousel view control as of yet?

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    Never tried...
    the first thing that comes to mind is to have, in your Model, a Property that return a ImageSource

    something like (not tested...)

    public ImageSource MyImageFromStream {
    
        get {
    
            return ImageSource.FromStream(() => new MemoryStream(Convert.FromBase64String("base64stringgoeshere")));
    
        }
    }
    

    and Bind this property to your Image in the ViewCell.... let me know...

  • @AlessandroCaliaro I have tried this. However I get an exception of not returning a view. System.InvalidOperationException: DataTemplate returned non-view content.

  • @AlessandroCaliaro We've decided to go a different route. Our deadline is fast approaching and we really needed to get something out. Once this project is complete I'll post some code up to GitHub for you to have a look at. Thank you for all your time, patience and knowledge.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    Ok,'post your github link when ready

  • percepticonpercepticon USMember ✭✭

    I'm just coming across this thread but for any other who find it and are using C# -

    you can also do something like this:

            ImageCarousel = new CarouselView
            {
                ItemSource = imageNames,
                ItemTemplate = new DataTemplate(typeof(Image)),
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.StartAndExpand
            };
    
            ImageCarousel.ItemTemplate.SetBinding(Image.SourceProperty, ".");
    

    best,

    percy

  • @bad.mathematician Your example looks good but I get an error because CarouselView has no property ItemTemplate.

    :(

Sign In or Register to comment.