Forum Xamarin Xamarin.Forms

Placing Label beneah ListView (It runs to the bottom)

EliranEliran USMember ✭✭✭

I have a ListView with few items.
I would like to place a label, RIGHT AFTER the end of the list (beneath the ListView)
Of some reason, the label shows in the BOTTOM of the screen.

 <StackLayout>
        <RefreshView Command="{Binding Commandy}"  IsRefreshing="{Binding IsRefreshingNow}">
            <ListView >
                <ListView.ItemsSource>
                    <x:Array Type="{x:Type x:String}">
                        <x:String>Item 1</x:String>
                        <x:String>Item 2</x:String>
                        <x:String>Item 3</x:String>
                        <x:String>Item 4</x:String>
                        <x:String>Item 5</x:String>
                        <x:String>Item 6</x:String>
                    </x:Array>
                </ListView.ItemsSource>
            </ListView>
        </RefreshView>
        <Label VerticalOptions="StartAndExpand" FontSize="Title" Text="{Binding Booly}"  d:Text="Hello"  />
</StackLayout>

This is how it looks like (The label is in the bottom).

Best Answer

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Do you want to get the result like following screenshot?

    Here is running code. Just add a VerticalOptions="Start" for StackLayout and HeightRequest="260" for ListView

       <StackLayout  VerticalOptions="Start" Spacing="0">
                <RefreshView   >
                    <ListView  HeightRequest="260"  >
                        <ListView.ItemsSource>
                            <x:Array Type="{x:Type x:String}">
                                <x:String>Item 1</x:String>
                                <x:String>Item 2</x:String>
                                <x:String>Item 3</x:String>
                                <x:String>Item 4</x:String>
                                <x:String>Item 5</x:String>
                                <x:String>Item 6</x:String>
                            </x:Array>
                        </ListView.ItemsSource>
                    </ListView>
                </RefreshView>
                <Label VerticalOptions="StartAndExpand" FontSize="Title" Text="testting"  d:Text="Hello"  />
            </StackLayout>
    
  • EliranEliran USMember ✭✭✭

    @LeonLu Thanks for the answer man.

    Yes, the picture you added is the desired outcome, BUT... I don't want to limit the list's height.
    The reason is that this list will be changed (by binding to a Target in code behind). It means
    the list's height will be changed.

    The goal is to see the label right after the end of the list, no matter what is the length of the list.

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    If you do not set the specific height for your listview, it cannot be achieve.

    I make a test to explain it, I set the green backgroundcolor for listview, when I add serveral label to the Stacklayout, listview will become samller. So if you do not add enough items in the Listview or enought Labels, you Label cannot beneath the ListView, Here is running GIF.

  • EliranEliran USMember ✭✭✭

    I see.
    Is there no way to set LIstView's height to the height which is suitable to the CURRENT amount of items?

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Agree with DimChris, you can add your Lable in your Listview.Footer to achieve it.

  • EliranEliran USMember ✭✭✭

    Works. Thank you very much guys B)

Sign In or Register to comment.