summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core/FileImageSource.cs
blob: f2f347199f0fe8e3509d88f30a22b18e037a87aa (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Threading.Tasks;

namespace Xamarin.Forms
{
	[TypeConverter(typeof(FileImageSourceConverter))]
	public sealed class FileImageSource : ImageSource
	{
		public static readonly BindableProperty FileProperty = BindableProperty.Create("File", typeof(string), typeof(FileImageSource), default(string));

		public string File
		{
			get { return (string)GetValue(FileProperty); }
			set { SetValue(FileProperty, value); }
		}

		public override Task<bool> Cancel()
		{
			return Task.FromResult(false);
		}

		public override string ToString()
		{
			return $"File: {File}";
		}

		public static implicit operator FileImageSource(string file)
		{
			return (FileImageSource)FromFile(file);
		}

		public static implicit operator string(FileImageSource file)
		{
			return file != null ? file.File : null;
		}

		protected override void OnPropertyChanged(string propertyName = null)
		{
			if (propertyName == FileProperty.PropertyName)
				OnSourceChanged();
			base.OnPropertyChanged(propertyName);
		}
	}
}