0

I am trying to load an image from a url string. Below code is an array of items, where Photo is what loads the image. Normally I included the image from my hard disk and loaded that image in by Photo = "image_name.jpg"

This is the first code:

public MainPageViewModel()
{        
    items.Add(new CardStackView.Item() { Name = "Title 1", Photo = " xxx ", Description = "Desc 1" });
    items.Add(new CardStackView.Item() { Name = "Title 2", Photo = " xxx ", Description = "Desc 2" });
    items.Add(new CardStackView.Item() { Name = "Title 3", Photo = " xxx ", Description = "Desc 3" });
    items.Add(new CardStackView.Item() { Name = "Title 4", Photo = " xxx ", Description = "Desc 4" });
    items.Add(new CardStackView.Item() { Name = "Title 5", Photo = " xxx ", Description = "Desc 5" });
    items.Add(new CardStackView.Item() { Name = "Title 6", Photo = " xxx ", Description = "Desc 6" });
}

I want xxx to be my url example https://i.vimeocdn.com/portrait/58832_300x300.

This piece of code is where I display the image:

Photo = new Image()
{
    InputTransparent = true,
    Aspect = Aspect.Fill,
    Scale = 0.95
};

view.Children.Add(Photo,
                  Constraint.RelativeToParent((parent) => { double w = parent.Width * 1; return ((parent.Width - w) / 2); }),
                  Constraint.Constant(10),
                  Constraint.RelativeToParent((parent) => { return parent.Width; }),
                  Constraint.RelativeToParent((parent) => { return (parent.Height* 0.80); }));  

Please note that these two pieces of code is not in the same file, but in two separate files.

I hope this isn't a duplicate, because I have not been able to find any solution to my problem.

6
  • 1
    Try github.com/luberda-molinet/FFImageLoading Commented Apr 7, 2017 at 7:06
  • What is the question or problem? Commented Apr 7, 2017 at 8:29
  • @EvZ "im trying to load an image from a url string." Commented Apr 7, 2017 at 8:45
  • @TheGejr So what is the problem with it? Does it crash the app? Does it simply not showing the image? Be more specific. Commented Apr 7, 2017 at 8:51
  • @EvZ no im trying to find a way to display the image, simply pasting a url doesn't seem to work? Commented Apr 7, 2017 at 9:02

2 Answers 2

1

You need to set the Source of your Image Element:

Photo = new Image()
{
    InputTransparent = true,
    Aspect = Aspect.Fill,
    Scale = 0.95,
    Source = "https://your_image_url.com/the_image.png"
};
Sign up to request clarification or add additional context in comments.

Comments

0

I recommend you to use Binding,Basically you need only to set value for the Source. try the following:

  <Image Source="{Binding ImageUrl}" WidthRequest="80" HorizontalOptions="Start" VerticalOptions="Start" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.