Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entry doesn't adopts LayoutOptions.StartAndExpand in horizontal context

I'd like to use an expanding Entry and a Button in a horizontal StackLayout:

var item = new StackLayout { 
    Orientation = StackOrientation.Horizontal,
    HorizontalOptions = LayoutOptions.FillAndExpand,
    Children = {

        new Entry { 
            Placeholder = "Feldtitel",
            VerticalOptions = LayoutOptions.Center,
            HorizontalOptions = LayoutOptions.StartAndExpand // NOTE THIS
        },
        new Button{ 
            Text = CFieldDescription.getNameForFieldType( fieldType ),
            VerticalOptions = LayoutOptions.Center,
            HorizontalOptions = LayoutOptions.End
        }

    }};

While the Entry is at the start, the Button is at the end, Xamarin.Forms doesn't change the size of Entry to fill the horizontal space:

enter image description here

Do I need to change my code? Or did I find a bug?

like image 622
SteAp Avatar asked Jun 08 '14 01:06

SteAp


1 Answers

Change the Entry.HorizontalOptions to LayoutOptions.FillAndExpand to get the desired effect:

var item = new StackLayout { 
    Orientation = StackOrientation.Horizontal,
    HorizontalOptions = LayoutOptions.FillAndExpand,
    Spacing = 12, //you probably want this
    Children = {
        new Entry { 
            Placeholder = "Feldtitel",
            VerticalOptions = LayoutOptions.Center,
            HorizontalOptions = LayoutOptions.FillAndExpand //there, fixed
        },
        new Button{ 
            Text = CFieldDescription.getNameForFieldType( fieldType ),
            VerticalOptions = LayoutOptions.Center,
            HorizontalOptions = LayoutOptions.End
        }
    }};

It looks like the LayoutOptions needs some good documentation.

like image 55
Stephane Delcroix Avatar answered Oct 16 '22 11:10

Stephane Delcroix