Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Adding image to StackLayout container failing if done using a local image from the .cs side

$
0
0

In my xaml file I am trying to set up a container that will house an unknown number of images, if I manually set an image inside there in the xaml file it works great:
<Image Source="Tamarin_portrait.JPG" WidthRequest="50" HeightRequest="50" Margin="10, 10, 10, 10"></Image>.

If I try to add a file from my cs side using an image online it works great:

var webImage = new Image { Source = ImageSource.FromUri(new Uri("https://xamarin.com/content/images/pages/forms/example-app.png")) }; imageContainer.Children.Add(webImage);

However if I try to add a local image to the imageContainer it fails to do so:
var locImage= new Image { Source = "Tamarin_portrait.JPG" }; //Or this way after declaring image without source-> locImage.Source = ImageSource.FromFile("Tamarin_portrait.JPG"); imageContainer.Children.Add(locImage);

I'm running it on android, and the image is located in the resources/drawable folder.

This feels like there's a simple mistake I'm making that I just don't see, can anyone shed some light on the problem?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>