Bug 32691 - Clearing an image by setting Image.Source to null, while Image.IsLoading is true, doesn't work.
Summary: Clearing an image by setting Image.Source to null, while Image.IsLoading is t...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 1.4.4
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Rui Marinho
URL:
Depends on:
Blocks:
 
Reported: 2015-08-01 17:08 UTC by Borislav Parvanov
Modified: 2015-10-09 09:20 UTC (History)
6 users (show)

Tags: AC
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

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