Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
File image markup extension V1
[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
You can’t perform that action at this time.