Reputation: 374
How can i make the AdaptiveGridView
view images from the web?
I only can let it view images that are already in my assets folder and when i try to set the source to be a link to an image, it just displays a white image and now download that image.
Upvotes: 1
Views: 271
Reputation: 15758
To show images form the web, we can take advantage of Image control. Image.Source supports http: or https: schemes and while setting the source to a URI value that can't be resolved to a valid image source file or decoding failures, it will fire an ImageFailed event. We can use this event to deal with potential errors. For more info, please see Remarks in Image.ImageFailed event.
Besides, in AdaptiveGridView Sample Page, it uses local assets for demonstration. We can easily change AdaptiveGridViewControl.ItemsSource
like following to use online images.
AdaptiveGridViewControl.ItemsSource = await new Data.PhotosDataSource().GetItemsAsync(true);
Also, as you are using UWP Community Toolkit, you can use ImageEx XAML Control instead of Image
control. This control downloads images asynchronously, while showing a loading indicator. Source images are then stored in the application’s local cache to preserve resources and load time. ImageEx also extends the default Image
Platform control to improve performance through caching. You can also use a placeholder image that will be displayed will loading the main image.
Upvotes: 1