private BitmapSource GetOrLoadImage(WeakReference <BitmapSource> weakReference, Func <BitmapSource> reload) { if (weakReference.TryGetTarget(out BitmapSource strongReference)) { return(strongReference); } else { var value = reload(); BitmapSourceStrongReferenceCache.RefreshReference(value); weakReference.SetTarget(value); return(value); } }
private void SetImage(WeakReference <BitmapSource> weakReference, BitmapSource value, [CallerMemberName] string propertyName = null) { BitmapSourceStrongReferenceCache.RefreshReference(value); weakReference.SetTarget(value); OnPropertyChanged(propertyName); }