Bengi Besceli
Bengi Besceli

Reputation: 3748

Xamarin image fills the page

Hello I'm developing a Xamarin.Forms application.
I have this code and the image fits to page on simulator.
How can I display the image in its original size?

var image = new Image { Aspect = Aspect.AspectFit};
image.Source = "image2.png";
Content = image;

Upvotes: 0

Views: 191

Answers (1)

Joehl
Joehl

Reputation: 3701

To set the dimensions of an image you can't use the Width and Height properties. Because the Width and Height properties are read-only (as the error said).

Try to use the WidthRequest and HeightRequest properties to set your desired dimension.

Infos from Xamarin-Developer-Page:

WidthRequest does not immediately change the Bounds of a VisualElement, however setting the WidthRequest will change the result of calls to GetSizeRequest, which will in turn modify the final size the element receives during a layout cycle.

Upvotes: 1

Related Questions