I'm trying to create a view that has several controls centered inside a StackLayout. When I have just one like this:
<StackLayout Orientation="Vertical" HorizontalOptions="Center" >
<controls:BindablePicker />
</StackLayout>
It works fine: Centered
However, when I try to add a ListView, e.g.:
<StackLayout Orientation="Vertical" HorizontalOptions="Center" >
<controls:BindablePicker />
<ListView HorizontalOptions="Center" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Orientation="Horizontal">
<controls:BindablePicker Title="Length" />
<controls:BindablePicker Title="Units" />
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
Everything is left justified and takes up the entire screen: Left justified
I'd like the widths of all controls to be as short as possible centered on the screen. Right now I'm using a ListView because I'm binding a list of objects and I thought that would be easier than trying to use a Grid.
Any suggestions would be greatly appreciated. Thanks.
UPDATE I updated my ViewCell to replace the StackLayout with a Grid, then put the ListView inside a grid as follows:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ListView Grid.Row="0" Grid.Column="1" HorizontalOptions="Center" SeparatorVisibility="None">
This is pretty much what I want, except the top picker is taking up the entire width of the screen, instead of being only as wide as it needs to be and centered.