Bug 32691

Summary: Clearing an image by setting Image.Source to null, while Image.IsLoading is true, doesn't work.
Product: Forms Reporter: Borislav Parvanov <borislav.parvanov>
Component: FormsAssignee: Rui Marinho <rui.marinho>
Status: RESOLVED FIXED    
Severity: normal CC: eric.maupin, jas, rui.marinho, seth.rosetter, stephane.delcroix, udhams
Priority: Normal    
Version: 1.4.4   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS   
Tags: AC Is this bug a regression?: ---
Last known good build:

Description Borislav Parvanov 2015-08-01 17:08:17 UTC
If we try to set Image.Source to null, while image is being loaded, that does not stop the load process, and once the image is fully loaded, it presents itself on the screen (notice that Image.Source is actually set to null, even though the image is present)

Here is an example to reproduce the issue:

1. Click the button and the image will start downloading. (a very large image is chosen so the loading process is longer) 
2. Once the label reads “LOADING” click the button again. This will set the Source to null.
3. Notice that after few seconds (that depends on the internet connection) the image will visualise.

using System;
using System.IO;
using Xamarin.Forms;

namespace TestImage
{
	public class App : Application
	{
		static void ClearImageCache ()
		{
			var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
			var cache = Path.Combine (documents, ".config", ".isolated-storage", "ImageLoaderCache");
			foreach (var file in Directory.GetFiles(cache)) {
				File.Delete (file); 
			}
		}

		public App ()
		{
			var label = new Label () { XAlign = TextAlignment.Center };
			var image = new Image ();

			image.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => {
				if (e.PropertyName == "IsLoading")
					label.Text = image.IsLoading ? "Loading" : "Done";
			};

			string kSetImageSource = "SET IMAGE SOURCE";
			string kClearImageSource = "CLEAR IMAGE SOURCE";

			var btnSetOrClear = new Button () { Text = kSetImageSource };

			btnSetOrClear.Clicked += delegate {
				if (btnSetOrClear.Text == kSetImageSource) {
					ClearImageCache ();
					image.Source = "https://upload.wikimedia.org/wikipedia/commons/3/3d/LARGE_elevation.jpg";
					btnSetOrClear.Text = kClearImageSource;
				} else {
					image.Source = null;
					btnSetOrClear.Text = kSetImageSource;
				}
			};

			MainPage = new ContentPage {
				Content = new StackLayout {
					Orientation = StackOrientation.Vertical, 
					Padding = new Thickness (10),
					Children = { btnSetOrClear, image, label }
				}
			};
		}
	}
}
Comment 1 Rui Marinho 2015-09-23 06:16:04 UTC
Should be fixed in 1.5.1-pre1
Comment 2 Rui Marinho 2015-09-23 06:16:15 UTC
Should be fixed in 1.5.1-pre1