Sunday, March 6, 2011

How to Check for Image in Cache Using Silverlight

I am creating a basic image browsing application using Silverlight. Depending on the user's connection speed, some images may take time to appear once they click on the thumb nail. I would like to show a progress bar while it is being downloaded. I have this part done.

However, if the image is already in the cache (viewing a previous image), I'd rather not have the progress bar flash up and then disappear. Is there a way to see if a particular file is in the cache before I display my progress bar?

From stackoverflow
  • After thinking about it for a while, I did come up with one solution, though it wasn't what I was originally intending.

    I am using the WebClient class to get my image file. I attach to the DownloadProgressChanged event. If the image has already been downloaded, then the ProgressPercentage is immediately 100.

    So instead of making the ProgressBar visibile when I call OpenReadAsync and making it invisible when the Completed event is fired, I set the visibility in the DownloadProgressChanged event handler.

0 comments:

Post a Comment