I try to add image to StackLayout via 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:App1;assembly=App1"
x:Class="App1.MainPage">
<RelativeLayout BackgroundColor="White">
<StackLayout Orientation="Horizontal" WidthRequest="1024" HorizontalOptions="Start" BackgroundColor="Magenta">
<Button BackgroundColor="Transparent" WidthRequest="50" BorderColor="Transparent" Image="menu.png">
</Button>
<Image Source="{local:ImageResource App1.Images.icon1.png}"/>
</StackLayout>
</RelativeLayout>
</ContentPage>
In this project I've added class for loading resource:
class ImageResourceExtention : IMarkupExtension
{
public string Source { get; set; }
public object ProvideValue(IServiceProvider serviceProvider)
{
if (Source == null)
{
return null;
}
var imageSource = ImageSource.FromResource(Source);
return imageSource;
}
}
Also in this project I've added icon1.png as Embedded Resource into Images folder.
Project name and assembly name are equal (App1).
Solution builds without problem but when I run application I get this error:
"Xamarin.Forms.Xaml.XamlParseException: <Timeout exceeded getting exception details>"
Where did I do mistake? Please help me, I'm beginner at xamarin