summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WP8/Converters/ImageConverter.cs
blob: 2e8bdef61c102b82e7153c7e8941a707c6befe5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Globalization;
using System.Threading.Tasks;

namespace Xamarin.Forms.Platform.WinPhone
{
	public class ImageConverter : System.Windows.Data.IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			var source = (ImageSource)value;
			IImageSourceHandler handler;

			if (source != null && (handler = Registrar.Registered.GetHandler<IImageSourceHandler>(source.GetType())) != null)
			{
				Task<System.Windows.Media.ImageSource> task = handler.LoadImageAsync(source);
				return new AsyncValue<System.Windows.Media.ImageSource>(task, null);
			}

			return null;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotSupportedException();
		}
	}
}