Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically show/hide Header or Footer of Xamarin.Forms.ListView

Is there a way to dynamically show/hide the header of a ListView based on a condition at runtime.

<ListView x:Name="ListViewChallenges" Header="{Binding .}">

    <ListView.FooterTemplate>
        <DataTemplate>
            <Label Text="No Elements found." IsVisible="{Binding FooterIsVisible}" />
        </DataTemplate>
    </ListView.FooterTemplate>

    <!-- ... -->

</ListView>

In the BindingContext I have declared the FooterIsVisible property. When it is false, the footer should be invisible. However this is not working, the Footer is always consuming a certain space for the Label at the bottom of the ListView.

Is this somehow possible?

like image 277
Florian Avatar asked Jan 27 '17 13:01

Florian


2 Answers

You should be able to hide the footer and not have it consume any space. I believe you'll need to set the HeightRequest for the label in the FooterTemplate. You can do that by doing something like:

<Label Text="No Elements found." IsVisible="{Binding FooterIsVisible}">
    <Label.Triggers>
        <Trigger TargetType="Label" Property="IsVisible" Value="False">
            <Setter Property="HeightRequest" Value="0" />
        </Trigger>
    </Label.Triggers>
</Label>
like image 129
Eugene Pawlik Avatar answered Nov 05 '22 16:11

Eugene Pawlik


If you want to hide the footer because the listview is empty just set

listview.footer = null
like image 25
Luis Paulino Avatar answered Nov 05 '22 16:11

Luis Paulino