diff options
Diffstat (limited to 'Xamarin.Forms.Core/ImageSourceConverter.cs')
-rw-r--r-- | Xamarin.Forms.Core/ImageSourceConverter.cs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core/ImageSourceConverter.cs b/Xamarin.Forms.Core/ImageSourceConverter.cs new file mode 100644 index 00000000..8ca829f7 --- /dev/null +++ b/Xamarin.Forms.Core/ImageSourceConverter.cs @@ -0,0 +1,18 @@ +using System; + +namespace Xamarin.Forms +{ + public sealed class ImageSourceConverter : TypeConverter + { + public override object ConvertFromInvariantString(string value) + { + if (value != null) + { + Uri uri; + return Uri.TryCreate(value, UriKind.Absolute, out uri) && uri.Scheme != "file" ? ImageSource.FromUri(uri) : ImageSource.FromFile(value); + } + + throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(ImageSource))); + } + } +}
\ No newline at end of file |