Image in ListView is not show only on Honor 7s Android Oreo 8.1

jancijanci Member ✭✭

I created Xamarin Forms 3.2 MVVM application. Application allows take o photo by camera and show photos in ListView.

Visual Studio Android project settings:

Compile using Android version: Android 8.1 Oreo

Android Manifest:

  • Minimum Android version: Android 5.0 (API Level 21)
  • Target Android version: Android 8.1 (API Level 27)

In view I have ListView control with Datatemplate which show only text and image.

        <ListView ItemsSource="{Binding Documents}"
                  Grid.Row="0"
                  Grid.ColumnSpan="3"
                  RowHeight="200">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid Margin="5">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"></RowDefinition>
                                <RowDefinition Height="*"></RowDefinition>
                            </Grid.RowDefinitions>


                            <Label Grid.Row="0" Text="{Binding FileName}" HorizontalTextAlignment="Center"></Label>

                            <Image Source="{Binding Image}"
                                   WidthRequest="100"
                                   HeightRequest="100"
                                   HorizontalOptions="Fill"
                                   VerticalOptions="Fill"
                                   Aspect="AspectFit" 
                                   Grid.Row="1"/>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

I bind to ListView ObservableCollection from ViewModel

    public ObservableCollection<DocumentViewModel> Documents
    {
        get => _documents;
        set
        {
            _documents = value;
            RaisePropertyChanged(nameof(Documents));
        }
    }

DocumentViewModel class

    public class DocumentViewModel : BindableBase
        {
            #region Fields

            private readonly Document _model;

            #endregion

            #region Contructors

            public DocumentViewModel(Document model)
            {
                _model = model;


                Image = ImageSource.FromStream(() => new MemoryStream(model.Data));
                Name = model.Name;
                FileName = model.FileName;
            }

            #endregion

            #region Image

            private ImageSource _image;

            public ImageSource Image
            {
                get => _image;
                set
                {
                    _image = value;
                    RaisePropertyChanged(nameof(Image));
                }
            }

            #endregion

            #region Name

            private string _name;

            public string Name
            {
                get => _name;
                set
                {
                    _name = value;
                    RaisePropertyChanged(nameof(Name));
                }
            }

            #endregion

            #region FileName

            private string _fileName;

            public string FileName
            {
                get => _fileName;
                set
                {
                    _fileName = value;
                    RaisePropertyChanged(nameof(FileName));
                }
            }

            #endregion
        }

Document model class

    public class Document
    {
        #region Properties

        public DateTime Created { get; set; }
        public string Name { get; set; }
        public string FileName { get; set; }
        public byte[] Data { get; set; }

        public int DocumentTypeId { get; set; }


        #endregion
    }

First I tested application in Android emulator Genymotion (Samsung Galaxy S8 Android 8.0).

It works good. Here is result.

Then I tested application on Assus Z00UD Android 6.0. It also works. Here is result.

Finally I tested application on Honor 7s Android version 8.1.

ListView does not show images only text.

Where can be root of problem? No error is show. Binding on ObservableCollection works because label text is not empty.

Thank you

Answers

  • Ahsan_SiddiqueAhsan_Siddique PKMember ✭✭✭✭

    Same with me when i try on my personal device 5.1 i got the same issue. But on other devices it worked fine.

  • CharwakaCharwaka INMember ✭✭✭✭

    @janci

    Have you tried updating Image on MainThread

    Device.BeginInvokeOnMainThread (() => {
    //
    });

Sign In or Register to comment.