Last active
February 19, 2019 10:43
-
-
Save MartinZikmund/5ed5b966b431955928e6cee31a3e5da4 to your computer and use it in GitHub Desktop.
File image markup extension V1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ContentProperty(nameof(Path))] | |
public class FileImageExtension : IMarkupExtension<FileImageSource> | |
{ | |
public string Path { get; set; } | |
public FileImageSource ProvideValue(IServiceProvider serviceProvider) => Convert(Path); | |
public static FileImageSource Convert(string path) | |
{ | |
if (path == null) throw new InvalidOperationException($"Cannot convert null to {typeof(ImageSource)}"); | |
if ( Device.RuntimePlatform == Device.UWP ) | |
{ | |
path = System.IO.Path.Combine("Assets/", path); | |
} | |
return (FileImageSource)ImageSource.FromFile(path); | |
} | |
object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) | |
{ | |
return ProvideValue(serviceProvider); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment