Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Force ListView to occupy all remaining vertical free space

$
0
0

I have a problem similar to the one expressed in this post: forums.xamarin.com/discussion/19874/listview-inside-stacklayout-a-height-problem. The solution mentioned in that post doesn't work for me.

I have a ContentViewthat contains a RelativeLayout, which contains a single StackLayout. This StackLayoutpartitions the area vertically into 2 sections. The lower section is a horizontal StackLayout that contains a pair of buttons, while the upper StackLayout contains a single ListView. I would like the height of the ListView to occupy the remaining vertical free space. Instead, the ListView is sized only to the height required to display the number of items currently bound to it. This is what it looks like:

ravib.com/download/xforms.listview.height.png

My XAML looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             x:Class="Xpoc.UI.EmployeePicker">
    <ContentView.Content>
        <RelativeLayout
            BackgroundColor="White">
            <StackLayout
                BackgroundColor="Aqua" Orientation="Vertical"
                VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
                Padding="0"
                RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, 
                                                Property=Width, Factor=1}"
                RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, 
                                                Property=Height, Factor=1}">

                <StackLayout
                    BackgroundColor="Green"
                    Orientation="Vertical"
                    VerticalOptions="StartAndExpand"
                    HorizontalOptions="CenterAndExpand">
                    <ListView
                        x:Name="_listEmployees" BackgroundColor="Red"
                        VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
                        ItemsSource="{Binding ShiftEditorViewModel.ShiftViewModel.AvailableEmployees}"
                        ItemTapped="OnEmployeeSelected">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <TextCell Text="{Binding EmployeeName}" />
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                </StackLayout>

                <StackLayout BackgroundColor="Yellow"
                    Orientation="Horizontal" VerticalOptions="EndAndExpand"
                    HorizontalOptions="CenterAndExpand">
                    <Button
                        x:Name="_btnUnfill" WidthRequest="150" TextColor="Black"
                        Text="Unfill" Font="Large"
                        Command="{Binding ShiftEditorViewModel.UnfillEmployeeCommand}" />
                     <Button
                        x:Name="_btnCancel" WidthRequest="150" TextColor="Black"
                        Text="Cancel" Font="Large"
                        Command="{Binding ShiftEditorViewModel.ShowShiftDetailsCommand}" />
                </StackLayout>

            </StackLayout>
        </RelativeLayout>
    </ContentView.Content>
</ContentView>

A nudge in the right direction would be greatly appreciated. Thanks.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>