ListView with optional Header/Footer

DarkwingDuckDarkwingDuck USMember ✭✭
edited November 2015 in Xamarin.Forms

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. :(

Answers

  • DarkwingDuckDarkwingDuck USMember ✭✭
    edited November 2015

    I forgot to mention that this is Xamarin Forms 1.5.1.6471 on iOS.

  • DarkwingDuckDarkwingDuck USMember ✭✭

    Sorry to bump my own thread but it would be nice to know that someone of Xamarin at least took notice of this.

Sign In or Register to comment.