diff options
Diffstat (limited to 'Xamarin.Forms.Core/PointTypeConverter.cs')
-rw-r--r-- | Xamarin.Forms.Core/PointTypeConverter.cs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core/PointTypeConverter.cs b/Xamarin.Forms.Core/PointTypeConverter.cs new file mode 100644 index 00000000..9b949988 --- /dev/null +++ b/Xamarin.Forms.Core/PointTypeConverter.cs @@ -0,0 +1,21 @@ +using System; +using System.Globalization; + +namespace Xamarin.Forms +{ + public class PointTypeConverter : TypeConverter + { + public override object ConvertFromInvariantString(string value) + { + if (value != null) + { + double x, y; + string[] xy = value.Split(','); + if (xy.Length == 2 && double.TryParse(xy[0], NumberStyles.Number, CultureInfo.InvariantCulture, out x) && double.TryParse(xy[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y)) + return new Point(x, y); + } + + throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(Point))); + } + } +}
\ No newline at end of file |