Aniket Sharma
Aniket Sharma

Reputation: 1020

Margin to a Image in Xamarin Forms

I have an image on my Xamarin.Forms. I want to add some margin from Top.

Form.XAML:-

<ContentPage.Content>
    <Grid>
        <Image x:Name="image" />
    </Grid>
</ContentPage.Content>"

Form.XAML.cs:-

image.Source = ImageSource.FromFile (Height > Width ? "portrait.jpg" : "landscape.jpg");

Upvotes: 2

Views: 8256

Answers (1)

irreal
irreal

Reputation: 2296

The current stable version of Xamarin.Forms, 2.2.0.31 supports the Margin property. It accepts a "Thickness" object which specifies the left, top, right and bottom sizes you want.

In XAML, the standard value converter is applied, which means you can specify Margin as one of these:

  • "10,20,30,40" - all the sides specifeid in order left, top, right, bottom
  • "10,20" - 10 units applied to left and right, 20 to top and bottom. Same as "10,20,10,20"
  • "10" - margin of 10 units is applied to all sides, same as "10,10,10,10"

More documentation is available here Margins and Padding

Upvotes: 10

Related Questions