ImageExBase.ProvideCachedResourceAsync(Uri, CancellationToken) Method

Definition

This method is provided in case a developer would like their own custom caching strategy for ImageExBase. By default it uses the built-in UWP cache provided by Windows.UI.Xaml.Media.Imaging.BitmapImage and the Image control itself. This method should return an Windows.UI.Xaml.Media.ImageSource value of the image specified by the provided uri parameter. A CancellationToken is provided in case the current request is invalidated (e.g. the container is recycled before the original image is loaded). The Toolkit also has an image cache helper which can be used as well: GetFromCacheAsync(Uri, Boolean, CancellationToken, List<KeyValuePair<String,Object>>) in ImageCache.

protected virtual System.Threading.Tasks.Task<Windows.UI.Xaml.Media.ImageSource> ProvideCachedResourceAsync (Uri imageUri, System.Threading.CancellationToken token);
abstract member ProvideCachedResourceAsync : Uri * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Windows.UI.Xaml.Media.ImageSource>
override this.ProvideCachedResourceAsync : Uri * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Windows.UI.Xaml.Media.ImageSource>
Protected Overridable Function ProvideCachedResourceAsync (imageUri As Uri, token As CancellationToken) As Task(Of ImageSource)

Parameters

imageUri
Uri

Uri of the image to load from the cache.

token
CancellationToken

A CancellationToken which is used to signal when the current request is outdated.

Returns

Task<Windows.UI.Xaml.Media.ImageSource>

Task

Examples

var propValues = new List<KeyValuePair<string, object>>();

if (DecodePixelHeight > 0)
{
    propValues.Add(new KeyValuePair<string, object>(nameof(DecodePixelHeight), DecodePixelHeight));
}
if (DecodePixelWidth > 0)
{
    propValues.Add(new KeyValuePair<string, object>(nameof(DecodePixelWidth), DecodePixelWidth));
}
if (propValues.Count > 0)
{
    propValues.Add(new KeyValuePair<string, object>(nameof(DecodePixelType), DecodePixelType));
}

// A token is provided here as well to cancel the request to the cache,
// if a new image is requested.
return await ImageCache.Instance.GetFromCacheAsync(imageUri, true, token, propValues);

Applies to