Is there a way to create a vertical stack layout with a button that takes 30% of of the parent, and a text input that takes 70% of the parent? Something like this:
<StackLayout Orientation="Vertical"> <Entry Height="70%"></Entry> <Button Height="30%">Click me</Button> </StackLayout>
But this doesn't work. Only solution so far is creating a complete Grid item and using that. Are there no other solutions?
A StackLayout organizes child views in a one-dimensional stack, either horizontally or vertically. By default, a StackLayout is oriented vertically. In addition, a StackLayout can be used as a parent layout that contains other child layouts.
The Xamarin. Forms FlexLayout is new in Xamarin. Forms version 3.0. It is based on the CSS Flexible Box Layout Module, commonly known as flex layout or flex-box, so called because it includes many flexible options to arrange children within the layout. FlexLayout is similar to the Xamarin.
The StartAndExpand , CenterAndExpand , EndAndExpand , and FillAndExpand values are used to define the alignment preference, and whether the view will occupy more space if available within the parent StackLayout . The default value of a view's HorizontalOptions and VerticalOptions properties is LayoutOptions. Fill .
StackLayout doesn't go very well with varying heights in this scenario. The Xamarin Forms engines isn't as well rounded as the WPF engine at this point. Basically you have to go
<Grid> <Grid.RowDefinitions> <RowDefinition Height="7*" /> <RowDefinition Height="3*" /> </Grid.RowDefinitions> <Entry Grid.Row="0" VerticalOptions="Fill"></Entry> <Button Grid.Row="1" VerticalOptions="Fill">Click me</Button> </Grid>
Also as a side note, only Grids can expand to the full width or height of its parent element. StackLayout's determine their maximum size by the sum of their children unless they are within a Grid and you put HorizontalOptions="Fill"
and VerticalOptions="Fill"
.
The only other way you could accomplish this is to get the DeviceHeight and Width from the OS and manually set the Heights of your elements. A complex and usually flawed approach, which I don't recommend.
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