James Montemagno
James Montemagno

Live, Love, Bike, and Code.

Live, Love, Bike, and Code

Share


Tags


Xamarin.Forms Image Caching in XAML

A lot of mobile applications have to deal with Images. There are a lot of awesome libraries for iOS and Android that will automatically download, optimize, and cache your images for you from a single line or two of code. Xamarin.Forms actually handles all of this for you automatically when you give the Image’s Source property an Image URL. You can read through the awesome documentation on the Xamarin developer portal. If you browse through this documentation you will see a section that says “Image Caching” and that is interesting. Xamarin.Forms actually handles image caching for you automatically for 1 day. You can enable or disable or extend this time easily in C#:

However, something that isn’t documentated just yet, although I will ping Craig about this, is how to do it in XAML. It is actually extremely simple as you can access all the properties of the Source including the ability to extend image caching. Here is what my image looks like with extending the image cache to 14 days:

Are you using Circle Images? Well you can still do it!

You can always adjust the CacheValidity=“14” as it just creates a new timespan in days for you.

Copyright © James Montemagno 2015 All rights reserved. Privacy Policy

View Comments