Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an image in UWP?

Tags:

c#

image

xaml

uwp

I have been looking online for hours trying to find a way to insert a simple image into my Universal Windows Application. All the tutorials I have found so far have been too confusing or just don't work.

Is there a way to insert an image into my XAML page that can be explained for someone new to developing Windows Apps? Do I need to initialize it in XAML and C#, or just through XAML?

like image 482
Andrew Avatar asked Aug 15 '16 18:08

Andrew


2 Answers

I had the same problem, where I only needed to just add simple picture get it over with, I'm assuming that you are using VS2017 if no, then I don't know if this solution will work, but if you are using VS2017 then do the following

fist add an image element for example <Image x:Name="img1" Width="100" Height="100" />

in the Universal Apps, there is a folder called Assets you will find it in the solution folder, also in the solution explorer, enter image description here right click on it in the solution explorer -> add existing item -> the photo you want

after you have added the photo, go to the img1 prosperities and in the source you will find the photo that was added inside the drop down list, keep in mind that there is already images in the assets

enter image description here you will find that the path for the image is added automatically in the Source attribute to the control img1 for example <Image x:Name="img1" Width="100" Height="100" Source="Assets/1.jpg" />

like image 127
ibr Avatar answered Oct 02 '22 12:10

ibr


Remember that when you want to insert a new image into Assets, you must go into the solution explorer, Assets->Add->New Item. If you insert the image manually, then you need to Add->existing item. Then select the image, rigth click, properties and in Build Action, make sure "content" is the default.

like image 32
El0din Avatar answered Oct 02 '22 12:10

El0din