【发布时间】:2021-02-22 12:15:53
【问题描述】:
我正在使用假 Api 来测试应用程序。Api 在此链接上:http://jsonplaceholder.typicode.com/。我连接我的应用程序,获取所有照片并添加到 CollectionView。一切正常,但没有显示图像。这是我的代码:
<Grid>
<StackLayout>
<Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0">
<Label Text="Welcome to Xamarin.Forms!" HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>
</Frame>
<RefreshView IsRefreshing="{Binding IsRefreshing, Mode=OneWay}"
Command="{Binding LoadRefreshCommand}">
<CollectionView ItemsSource="{Binding Photos}" SelectedItem="{Binding SelectedPhoto}" >
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="0,0,5,0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={x:Reference CurrentPage}, Path=BindingContext.LoadPhotosCommand}" />
</Grid.GestureRecognizers>
<Image Source="{Binding Url}" Grid.Column="0"></Image>
<Frame HasShadow="False" VerticalOptions="Center" Grid.Column="1">
<Label Text="{Binding Title}"></Label>
</Frame>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</RefreshView>
</StackLayout>
<StackLayout HorizontalOptions="CenterAndExpand" VerticalOptions="Center">
<Frame IsVisible="{Binding IsBusy}" BorderColor="#07987f" HasShadow="False" BackgroundColor="#eeeeee">
<StackLayout>
<ActivityIndicator IsVisible="{Binding IsBusy}" IsRunning="{Binding IsBusy}" HorizontalOptions="Center" VerticalOptions="Center"></ActivityIndicator>
<Label TextColor="#07987f" Text="Loading Data, Please Wait..." HorizontalTextAlignment="Center" VerticalTextAlignment="Center" HorizontalOptions="Center" VerticalOptions="Center" IsVisible="{Binding IsBusy}"/>
</StackLayout>
</Frame>
</StackLayout>
</Grid>
这是我从调试应用程序获得的图像:
可能是什么问题或所有图像都是空白的。 我也在控制台中得到了这个:
[0:] HTTP Request: Could not retrieve https://via.placeholder.com/600/f66b97, status code Gone
[0:] ImageLoaderSourceHandler: Could not retrieve image or image data was invalid: Uri: https://via.placeholder.com/600/f66b97
有人遇到过同样的问题吗?
【问题讨论】:
-
"via.placeholder.com/600/f66b97" 返回 304 状态码
-
@Jason 304 未修改是什么意思?
-
@Jason 有什么建议可以解决这个问题吗?
-
使用不同的服务。听起来返回的图像 url 行为不正常
-
@Jason 图片网址看起来不错
标签: c# image xamarin.forms dotnet-httpclient imagesource