Forum Xamarin.Forms

Image control, a new Aspect value to use size of the image

AndrewMobileAndrewMobile USMember ✭✭✭✭
edited June 2017 in Xamarin.Forms

Summary

The Aspect property of the Image control (surprisingly) does not have a value to make the Image control use the size of its image given by Source property.
If you look to WPF, there's Stretch.None https://msdn.microsoft.com/en-us/library/system.windows.media.stretch(v=vs.110).aspx

I can't see a way currently to do this in Xamarin Forms. The only workaround I can see is to set WidthRequest and HeightRequest on the Image contrrol, but it's not nice, and it only works if you know the image size.

API Changes

My suggestion is to have a new Aspect enumeration value, called None.

The way it should work in code and XAML is pretty straightforward:

C#:

Image image = new Image() 
{
     Aspect = None              
};

XAML:

<Image Source="myImage" 
              Aspect="None" />

Intended Use Case

Preserve image original size.

Tagged:

Open · Last Updated

Posts

  • VelocityVelocity NZMember ✭✭✭
    edited June 2017

    You can of course create an extended image with an Aspect property and then support it in each custom renderer, however I do agree this would be a useful addition to the stock XF Image control.

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    @Velocity Thanks. I am not looking into workarounds. There's so many workarounds/libraries to different things just because it's not in the framework.

Sign In or Register to comment.