Skip to content

Commit 8239841

Browse files
Updated method name and provided more guidance in comments.
1 parent 9c1dcdf commit 8239841

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.Core/ImageEx/ImageExBase.Source.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public partial class ImageExBase
2525
public static readonly DependencyProperty SourceProperty = DependencyProperty.Register(nameof(Source), typeof(object), typeof(ImageExBase), new PropertyMetadata(null, SourceChanged));
2626

2727
/// <summary>
28-
/// Gets value tracking the currently requested source Uri. This can be helpful to use when implementing <see cref="ProvideCachedResourceAsync(Uri)"/> where loading an image from a cache takes longer and the current container has been recycled and is no longer valid since a new image has been set.
28+
/// Gets value tracking the currently requested source Uri. This can be helpful to use when implementing <see cref="AttachCachedResourceAsync(Uri)"/> where loading an image from a cache takes longer and the current container has been recycled and is no longer valid since a new image has been set.
2929
/// </summary>
3030
protected Uri CurrentSourceUri { get; private set; }
3131

@@ -143,7 +143,7 @@ private async Task LoadImageAsync(Uri imageUri)
143143
{
144144
if (IsCacheEnabled)
145145
{
146-
await ProvideCachedResourceAsync(imageUri);
146+
await AttachCachedResourceAsync(imageUri);
147147
}
148148
else if (string.Equals(imageUri.Scheme, "data", StringComparison.OrdinalIgnoreCase))
149149
{
@@ -171,8 +171,13 @@ private async Task LoadImageAsync(Uri imageUri)
171171
/// <summary>
172172
/// This method is provided in case a developer would like their own custom caching strategy for <see cref="ImageExBase"/>.
173173
/// By default it uses the built-in UWP cache provided by <see cref="BitmapImage"/> and
174-
/// the <see cref="Image"/> control itself. Call <see cref="AttachSource(ImageSource)"/> to set
175-
/// the retrieved cache value to the image.
174+
/// the <see cref="Image"/> control itself. This method should call <see cref="AttachSource(ImageSource)"/>
175+
/// to set the retrieved cache value to the image. <see cref="CurrentSourceUri"/> may be checked
176+
/// after retrieving a cached image to ensure that the current resource requested matches the one
177+
/// requested by the <see cref="AttachCachedResourceAsync(Uri)"/> parameter.
178+
/// <see cref="OnNewSourceRequested(object)"/> may be used in order to signal any cancellation events
179+
/// using a <see cref="CancellationToken"/> to the call to the cache, for instance like the Toolkit's
180+
/// own <see cref="CacheBase{T}.GetFromCacheAsync(Uri, bool, CancellationToken, List{KeyValuePair{string, object}})"/> in <see cref="ImageCache"/>.
176181
/// </summary>
177182
/// <example>
178183
/// <code>
@@ -201,7 +206,7 @@ private async Task LoadImageAsync(Uri imageUri)
201206
/// {
202207
/// // If you have many imageEx in a virtualized ListView for instance
203208
/// // controls will be recycled and the uri will change while waiting for the previous one to load
204-
/// if (_currentSourceUri == imageUri)
209+
/// if (CurrentSourceUri == imageUri)
205210
/// {
206211
/// AttachSource(img);
207212
/// ImageExOpened?.Invoke(this, new ImageExOpenedEventArgs());
@@ -217,7 +222,7 @@ private async Task LoadImageAsync(Uri imageUri)
217222
/// {
218223
/// lock (LockObj)
219224
/// {
220-
/// if (_currentSourceUri == imageUri)
225+
/// if (CurrentSourceUri == imageUri)
221226
/// {
222227
/// ImageExFailed?.Invoke(this, new ImageExFailedEventArgs(e));
223228
/// VisualStateManager.GoToState(this, FailedState, true);
@@ -228,8 +233,9 @@ private async Task LoadImageAsync(Uri imageUri)
228233
/// </example>
229234
/// <param name="imageUri"><see cref="Uri"/> of the image to load from the cache.</param>
230235
/// <returns><see cref="Task"/></returns>
231-
protected virtual Task ProvideCachedResourceAsync(Uri imageUri)
236+
protected virtual Task AttachCachedResourceAsync(Uri imageUri)
232237
{
238+
// By default we just use the built-in UWP image cache provided within the Image control.
233239
AttachSource(new BitmapImage(imageUri));
234240

235241
return Task.CompletedTask;

0 commit comments

Comments
 (0)