Customize Image Source URL path

LuisPulidoLuisPulido USUniversity
edited January 2017 in Xamarin.Forms

Hi! This is my first question in the forums and I got to this point because I've found no help anywhere.

The story is as follows:

  • I get an object from web that has an ImageURL property
  • I have an online resizer (imagine something like myresizer.com/image=[ImageURL]&size=[size] that will return a resized image)
  • I have in my Xaml something like: <Image Source="{Binding ImageURL}">

Now, I want to change that source to a string something like "myresizer.com/image="imageurl"&size"300""

I don't know many ways to do this, if you have a better idea, please let me know, but what I thought of the following solution:

  • Having a class (named ImageResized) that inherits from "Xamarin.Forms.Image" and overrides the source url to something like:
    (pseudocde) Source = string.format{"myresizer.com/image=\"{0}\"&size=\"{1}\"", Source, "300");

  • In my xaml I use ImageResized instead of image like this: <local:ImageResized Source="{Binding ImageURL}>"

Once I have that, I guess that adding a new property like the size to my ImageResized wouldn't be much trouble, and if you can help me with that so I can do <local:ImageResized Source="{Binding ImageURL} Size="{Binding ImageSize}>" I will really appreciate!

Thank you in advance for any help!

Best Answer

Answers

  • LuisPulidoLuisPulido USUniversity
    edited January 2017

    @JohnMiller Thank you! Sorry for coming back late, but I wanted to say that it worked, I had to read a bit more to learn about converters, I failed many times but in the end I got a great result, I'm glad you didn't give me a full answer but pointed into the right direction, I learned a lot.

    I even used the parameter to send an object with the resize information to the converter!

    Thanks again!

Sign In or Register to comment.