user3247130
user3247130

Reputation: 71

How can I add and use image in Visual Studio 2017?

I have found many solutions, but for old versions and other platforms, that don't work. Am using Xaramin Forms to have cross-platform usage.

Currently: portable project has all pictures in a folder called "Images". (eg. 'logo.png').

tried:

XAML: <Image x:Name="imgLogo" Source="/Images/logo.png"> - Not displayed


C#: imgLogo.Source = "/Images/logo.png"; - Not displayed either

Since it is only for appearance, not dynamic, XAML should be fine.

Also I'd like have the image clickable. So how should I wrap in a button?

PART 2: ANOTHER (FUTURE) STEP

What is the simplest way to have a few sliding images? I have a string array of filenames...

Upvotes: 0

Views: 7546

Answers (2)

Pangi Min
Pangi Min

Reputation: 69

I think you are using absolute path.

Change to relative path.

ex :

<Image x:Name="imgLogo" Source="../Images/logo.png"> 

You can display image to your SW.

Upvotes: 0

Timo Salom&#228;ki
Timo Salom&#228;ki

Reputation: 7189

If you want to have Images within your PCL project, they need to be Embedded resources but you need to jump through some hoops to call them via XAML. Take a look at the Embedded Images section of the Images article on official Xamarin documentation.

  1. You need an IMarkupExtension that finds the image resource specified in XAML.
  2. You can then call images like this: <Image Source="{local:ImageResource WorkingWithImages.beach.jpg}" />

Regarding the sliding images, take a look at the CarouselView control that let's you swipe through (for example) a list of images.

Upvotes: 0

Related Questions