question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Image stream not being displayed in carousel

See original GitHub issue

I am having an issue, hopefully someone has the answer and lets me know if I’m doing anything wrong or it’s a limitation of the carousel.

The idea is that I have several images being generated at runtime (qr barcodes), and I want to display those images along with some text in a carouselview.

The problem

This is what I see on the first load

1

As you can see the text is displayed, the items within the collection are there, and the same images outside the carousel exist.

The funny thing is that when I save the XAML again (while debugging) forcing a hot reload, it refreshes the page and I can see it working as expected.

2

I suspect there must be some kind of race condition here, but why isn’t the carousel displaying the images?

My code

For example, my view model has the observable collection of ImageSource that I feed when the view model is instantiated:

private readonly IQrGeneratorService _qrGeneratorService;
private ObservableCollection<ImageSource> _images = new ObservableCollection<ImageSource>();

public ObservableCollection<ImageSource> Images
{
    get => _images;
    set
    {
        _images = value;
        OnPropertyChanged();
    }
}

public MainViewModel(IQrGeneratorService qrGeneratorService)
{
    _qrGeneratorService = qrGeneratorService;
    _qrGeneratorService = qrGeneratorService;
    var oneBytes = _qrGeneratorService.GetQrCode("foo");
    var twoBytes = _qrGeneratorService.GetQrCode("bar");
    var threeBytes = _qrGeneratorService.GetQrCode("tor");

    var one = ImageSource.FromStream(() => new MemoryStream(oneBytes));
    var two = ImageSource.FromStream(() => new MemoryStream(twoBytes));
    var three = ImageSource.FromStream(() => new MemoryStream(threeBytes));
    Images.Add(one);
    Images.Add(two);
    Images.Add(three);
}

Now my Xaml bound to this view model with the following code behind

public partial class MainPage : ContentPage
    {
        private readonly MainViewModel _mainViewModel = AppContainer.Resolve<MainViewModel>();
        public MainPage()
        {
            InitializeComponent();
            BindingContext = _mainViewModel;
        }
    }

has the following XAML

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:viewModels="clr-namespace:Sasw.AforoPass.ViewModels;assembly=Sasw.AforoPass"
             xmlns:panCardView="clr-namespace:PanCardView;assembly=PanCardView"
             xmlns:controls="clr-namespace:PanCardView.Controls;assembly=PanCardView"
             mc:Ignorable="d"
             x:Class="Sasw.AforoPass.Views.MainPage" 
             x:DataType="viewModels:MainViewModel">
    <ContentPage.Content>
        <StackLayout>
            <StackLayout.Resources>
                <ResourceDictionary>
                    <ResourceDictionary.MergedDictionaries>
                        <ResourceDictionary Source="/Styles/Styles.xaml" />
                    </ResourceDictionary.MergedDictionaries>
                </ResourceDictionary>
            </StackLayout.Resources>

            <panCardView:CarouselView 
                ItemsSource="{Binding Images}"
                BackgroundColor="{StaticResource ColorPrimary}"
                HorizontalOptions="FillAndExpand"
                VerticalOptions="FillAndExpand">
                <panCardView:CarouselView.ItemTemplate>
                    <DataTemplate>
                        <StackLayout 
                            HorizontalOptions="CenterAndExpand" 
                            VerticalOptions="CenterAndExpand">
                            <Image Source="{Binding .}"></Image>
                            <Label Text="image should be here"></Label>
                        </StackLayout>
                    </DataTemplate>
                </panCardView:CarouselView.ItemTemplate>

                <controls:LeftArrowControl />
                <controls:RightArrowControl />
                <controls:IndicatorsControl ToFadeDuration="1500"/>
            </panCardView:CarouselView>
            <Image WidthRequest="20" HeightRequest="20" Source ="{Binding Images[0]}"></Image>
            <Image WidthRequest="20" HeightRequest="20"  Source ="{Binding Images[1]}"></Image>
            <Image WidthRequest="20" HeightRequest="20"  Source ="{Binding Images[2]}"></Image>
   
            <Button Text="Close"></Button>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

Some things to notice

It could be due to the fact that the image is an ImageSourceStream and that the stream is not ready by the time the carousel is rendered. Maybe the image source itself should be observable? But I can see the images outside the carousel, so I’m not sure.,

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
AndreiMisiukevichcommented, Jun 5, 2020

I added this comment to StackOverflow as well. Perhaps it would be helpful for others

0reactions
diegosaswcommented, Jun 5, 2020

yes it does. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

jquery - Bootstrap Carousel does not show
For some unidentifiable reason, my Bootstrap carousel is not showing anything but its image contents, no carousel interface whatsoever.
Read more >
Why don't the Homepage Carousel images display properly?
Likely Cause: There are two possible reasons for this. Different sized images. ... As the images transition from one image to the next,...
Read more >
SharePoint Online Communication Site- Image Carousel ...
I working on a SharePoint Online Communication Site. I am trying to add an Image Gallery webpart on the page that is set...
Read more >
How To Use Image SlideShow In Streamlabs OBS - YouTube
I'll show how to add the photos, the different settings, ... ℹ️ Elgato Stream Deck Tutorials https://tinyurl.com/y824ufw2 ℹ️ OBS Studio ...
Read more >
How to Build an Image Carousel Component with ...
In their user interfaces, movies and series titles are arranged so that the titles are clearly visible. In this tutorial, I'll guide you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found