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

ListView with optional Header/Footer

$
0
0

I'm trying to show a header (or footer - not a group header!) in a ListView, but only if it is necessary. A simple example would be a message with a 'dismiss' button next to it which hides the message.

This is what I tried:

< ListView Header="{Binding Message}">
< ListView.HeaderTemplate>
< DataTemplate>
< StackLayout Padding="10">
< Label Text="{Binding}" />
< Button Text="Dismiss" Clicked="DismissClicked" />
< /StackLayout>
< /DataTemplate>
< /ListView.HeaderTemplate>
< /ListView>

In my ViewModel I set Message to a String when I want to display a message, in DismissClicked I set to null to hide it.
But this does not add or remove the header dynamically as I expected, instead it does nothing. What am I doing wrong or is it a bug?

I tried to work around this by setting Message to an empty string (now the header is there!) and hide or show the StackPanel myself in OnBindingContextChanged. But the ListView won't collapse the header so there's empty space where the StackPanel used to be. :(


Viewing all articles
Browse latest Browse all 91519

Trending Articles



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