I am having difficulty bringing up an image on the content page in a stack layout. I looked through Xamarin API Documentation and found Xamarin.Forms.Image.Source Property, but no sample code to see how it's written. I also checked to see how it was written in C# and seems to match my code in terms of filename path, but in Xamarin, it may be slightly different since it's the first time doing this. The code I'm currently testing through an Android emulator (Google Nexus 5) in Visual Studio 2013 which runs fine, with the exception of the Image not showing.
Image Source:
new Image
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
Source = "/Assets/xamarin_logo.png",
},
Full Code:
public NFCPage()
{
StackLayout stackLayout = new StackLayout // instantiate a StackLayout object to layout its children
{
Spacing = 5, // amount of spae between each child element
//HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.FillAndExpand, // defines how the elements should be laid out; fill the entire width of the content to the screen
BackgroundColor = Color.Blue,
Children = // gets a list of child elements
{
new Label
{
TextColor = Color.White,
BackgroundColor = Color.Red,
XAlign = TextAlignment.Center, // set text alignment horizontally
Text = "Google",
},
new Label
{
Text = "Place your device directly at the symbol.",
XAlign = TextAlignment.Center,
TextColor = Color.White,
},
new Image
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
Source = "/Assets/xamarin_logo.png",
},
new Button
{
Text = "QR Code",
TextColor = Color.White,
},
new Button
{
Text = "?",
TextColor = Color.White,
},
}
};
Content = stackLayout; // apply stackLayout to Content
}