0
votes

Today I've updated Xamarin Forms to 4.1 version and the images from web are not loading anymore. I've tried to restart VS (for mac), cleaned the solution and rebuilt it, completly remove the app from my cellphone and even restart the device but nothing seems to work.

Here is the XAML markup

  <ListView
     x:Name="campaignsListView"
     HasUnevenRows="True"
     RelativeLayout.WidthConstraint="{ConstraintExpression
         Type=RelativeToParent,
         Property=Width,
         Factor=1}">
     <ListView.ItemTemplate>
         <DataTemplate>
             <ViewCell>
                 <Frame CornerRadius="10"
                     RelativeLayout.WidthConstraint="{ConstraintExpression
                         Type=RelativeToParent,
                         Property=Width,
                         Factor=1}">
                        <StackLayout Orientation="Vertical">
                            <Image
                                BackgroundColor="Aqua"
                                HeightRequest="150"
                                HorizontalOptions="FillAndExpand"
                                Source="{Binding CampaignImage}"></Image>
                            <Label

                             HorizontalOptions="CenterAndExpand"
                             Text="{Binding CampaignImage}"></Label>
                        </StackLayout>
                     </Frame>
             </ViewCell>
         </DataTemplate>
     </ListView.ItemTemplate>
 </ListView>

I don'be believe that any binding error is occuring, as I ended upfor debugging purpose, binding the Image URL to a label and it works fine

Image I'm trying to load https://www.editorajuspodivm.com.br/cdn/imagens/produtos/original/produto-teste-marcador-de-paginas-1154410cb043c754d9e2ada9fed04650.png

EDIT: I noticed that my VS updates were coming from Preview Channel, I changed to Stable channel, did all the updates and now everything is fine again. As the builds where Previews I believe that maybe something were still buggy

2
Where and how did you set the ItemsSource?Jaymin

2 Answers

0
votes

CampaignImage must set as uri CampaignImageUri

CampaignImageUri = New Uri(CampaignImage):

0
votes

I have created a demo to test your code with Xamarin.forms 4.1 and it works well. Here is the code.

ImageViewModel.cs

class ImageViewModel : INotifyPropertyChanged
{
    public string _image;
    public string image
    {
        get
        {
            return _image;
        }
        set
        {
            if (_image != value)
            {
                _image = value;
                NotifyPropertyChanged();
            }
        }
    }
    public string _imageName;
    public string imageName
    {
        get
        {
            return _imageName;
        }
        set
        {
            if (_imageName != value)
            {
                _imageName = value;
                NotifyPropertyChanged();
            }
        }
    }


    protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    public event PropertyChangedEventHandler PropertyChanged;
}

page.xaml.cs

ObservableCollection<ImageViewModel> imageViewModels = new 
ObservableCollection<ImageViewModel>();

    public Page1()
    {
        InitializeComponent();
        imageViewModels.Add(new ImageViewModel
        {
            image = "https://www.editorajuspodivm.com.br/cdn/imagens/produtos/original/produto-teste-marcador-de-paginas-1154410cb043c754d9e2ada9fed04650.png",
            imageName = "Image1"
        });

        campaignsListView.ItemsSource = imageViewModels;
    }

xaml is the same with yours.

<StackLayout Orientation="Vertical">
     <Image BackgroundColor="Aqua" HeightRequest="150"      
            HorizontalOptions="FillAndExpand" Source="{Binding image}"></Image>
     <Label HorizontalOptions="CenterAndExpand" Text="{Binding imageName}"></Label>
</StackLayout> 

Note: Define image url to string type.