locked
Add Image to XAML dynamically on WP8.1

    Question

  • Hi,

    Can someone explain me the right way to add an image to the XAML page dynamically? It was easy on WP8 and now I always get some errors or I can't see an image on the app, when executed.

    On my XAML I have a Stackpanel:

    <Stackpanel x:Name:"container"></Stackpanel>

    Now, I want to create an image in C#:

    Image img = new Image(); BitmapImage bmp = new BitmapImage(new Uri("Assets/image.png", UriKind.Relative)); img.Height = 100; img.Width = 100; img.Source = bmp;

    container.Childrens.Add(img);

    This was a working code on WP8. But now this code doesn't work anymore. it give me an error, that the Uri can't be anymore relative on WP8.1 and it must be assolute. But I can't find any example for WP8.1 on the web and on the other 100 examples on the web, no one will work.

    I was trying it for 2-3 hours... How is it possible that after 3 hours, I am still not able to load an image?????? The new libraries seems to be impossible to learn or use.




    Friday, August 8, 2014 12:40 PM

Answers