Search code examples
windows-phone-8xamarin.iosxamarinxamarin.androidxamarin.forms

How can I create right-aligned items in the ui with Xamarin.Forms?


I try create this page with StackLayout and Grid, but I can't align rightы controls to right side. Maybe I should use RelativeLayout? But I don't know how align controls to right side

this is my page: http://s9.postimg.org/z5ilck6hb/template.png

UPD. I solved this problem by putting StackLayout with HorizontalOptions = LayoutOptions.EndAndExpand to each grid cell (in the right column)


Solution

  • If you want to align your controls to the right, try using

    HorizontalOptions="EndAndExpand"
    

    Using the grid control, you have more control over the alignment because you can create multiple columns (of varying width).

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition  Height="40" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100" />
            <ColumnDefinition Width="100" />
            <ColumnDefinition Width="80" />
        </Grid.ColumnDefinitions>
    

    You can find out more on My blog

    Thanks.

    -jesse

    In your subsequent question about aligning the first column to the left and the second to the right, just use horizontal Alignment Start and End respectively (on your element (label) not on the grid).