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).
You can easily yous Listview.Footer
<ListView x:Name="listView"> <ListView.ItemTemplate> <DataTemplate> <TextCell Text="{Binding Name}" Detail="{Binding Description}"></TextCell> </DataTemplate> </ListView.ItemTemplate> <ListView.Footer> <Label Text="Footer" /> </ListView.Footer> </ListView>
Answers
Do you want to get the result like following screenshot?
Here is running code. Just add a
VerticalOptions="Start"
forStackLayout
andHeightRequest="260"
forListView
@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.
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 serverallabel
to theStacklayout
,listview
will become samller. So if you do not add enough items in theListview
or enoughtLabel
s, youLabel
cannot beneath theListView
, Here is running GIF.I see.
Is there no way to set LIstView's height to the height which is suitable to the CURRENT amount of items?
You can easily yous Listview.Footer
Agree with DimChris, you can add your
Lable
in yourListview.Footer
to achieve it.Works. Thank you very much guys