Skip to content

Instantly share code, notes, and snippets.

@SnowyPainter
Created February 8, 2021 01:56
Show Gist options
  • Save SnowyPainter/60fac19ce4581df6d8e336a6c339b93a to your computer and use it in GitHub Desktop.
Save SnowyPainter/60fac19ce4581df6d8e336a6c339b93a to your computer and use it in GitHub Desktop.
using System;
using System.Reflection;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace HeVibrates
{
[ContentProperty (nameof(Source))]
class ImageResourceExtension:IMarkupExtension
{
public string Source { get; set; }
public object ProvideValue(IServiceProvider serviceProvider)
{
if (Source == null) return null;
var imgSource = ImageSource.FromResource(Source, typeof(ImageResourceExtension).GetTypeInfo().Assembly);
return imgSource;
}
}
}
//xmlns:local ="clr-namespace:PROJECTNAME"
//<Image Source="{local:ImageResource Source=PROJCETNAME.IMAGEPATH}"/>
//IMAGEPATH = Folder.Image.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment