Upon inspecting the Microsoft Docs for this, it is not as easy as just specifying the path.
First, Create an IMarkupExtension
[ContentProperty (nameof(Source))]
public class ImageResourceExtension : IMarkupExtension
{
public string Source { get; set; }
public object ProvideValue (IServiceProvider serviceProvider)
{
if (Source == null)
{
return null;
}
// Do your translation lookup here, using whatever method you require
var imageSource = ImageSource.FromResource(Source, typeof(ImageResourceExtension).GetTypeInfo().Assembly);
return imageSource;
}
}
Then consume it in your XAML:
<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:WorkingWithImages;assembly=WorkingWithImages"
x:Class="WorkingWithImages.EmbeddedImagesXaml">
<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
<!-- use a custom Markup Extension -->
<Image Source="{local:ImageResource WorkingWithImages.beach.jpg}" />
</StackLayout>
</ContentPage>
Note that you have to add a custom namespace to your page, in this case: xmlns:local="clr-namespace:WorkingWithImages;assembly=WorkingWithImages"
MyXamarinProject.folder.logo.jpg- Gerald VersluisBuild Actionwas set as AndroidAsset and was not displaying. I saw this post and changed it to AndroidResource and bewm, I got my image [displayed]. - Scott Fraley