Bind Image Source to web address is not problem, it will works well... until You don't care about performance. Problem will appear if You want to cache images. Isolated storage is only way to store downloaded files in Silverlight not matter Browser or Windows Phone. Not so difficult to download image file from Internet and save to Isolated Storage, but how to use it in Silverlight Page?
Well, lets try to figure out. First define image converter:
- public class IsoImageConverter : IValueConverter
- {
- //Convert Data to Image when Loading Data
- public object Convert(object value, Type targetType, object parameter,
- System.Globalization.CultureInfo culture)
- {
- var bitmap = new BitmapImage();
- try
- {
- var path = (string)value;
- if (!String.IsNullOrEmpty(path))
- {
- using (var file = LoadFile(path))
- {
- bitmap.SetSource(file);
- }
- }
- }
- catch
- {
- }
- return bitmap;
- }
- private Stream LoadFile(string file)
- {
- using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
- {
- return isoStore.OpenFile(file, FileMode.Open, FileAccess.Read);
- }
- }
- public object ConvertBack(object value, Type targetType, object parameter,
- System.Globalization.CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
Next define link in App.xaml for use in XAML code
- <local:IsoImageConverter x:Key="IsoImageCoverter"/>
And finally bind to string path to Isolated Storage image file
- <Image Source="{Binding ImagePath, Converter={StaticResource IsoImageCoverter}}"/>
Work Fine!(* ̄∇ ̄*)
ReplyDeleteThanks
I have a list of images. How can i use this with it
ReplyDeleteYou have provided valuable data for us. It is great and informative for everyone. Keep posting always. I am very thankful to you. vector image software mac
ReplyDelete