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:

Do I need to change my code? Or did I find a bug?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With