Home > database >  Xamarin Image not Loading
Xamarin Image not Loading

Time:01-25

I am trying to display a list of images with different sizes and i want to display them with there full height and width, but the images are not loading on the screen if i didn't specified the height in the image control.

code :

 <Grid>
        <CollectionView ItemsSource="{Binding ImgList}">
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Grid RowDefinitions="Auto,Auto" ColumnDefinitions="Auto,*">
                        <Label>Image:</Label>
                        <Image Grid.Row="1" Grid.ColumnSpan="2" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Aspect="AspectFill" Source="{Binding .}"></Image>
                    </Grid>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>
    </Grid>

note: ImgList is an observableCollection of Images name string.

CodePudding user response:

You could refer to the code below. You could check the image location and binding. I put the image in Android Resource/Drawable folder.

Xaml: The same xaml with yours.

Code behind:

 public ObservableCollection<string> ImgList { get; set; }
    public Page10()
    {
        InitializeComponent();
        ImgList = new ObservableCollection<string>() { "image.jpeg", "image.jpeg" };
        this.BindingContext = this;
    }

CodePudding user response:

Can you please make sure if you load images from your code project than you need to give Whole Path from root.

Can you please also check that Build Action of images.

  •  Tags:  
  • Related