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?
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>
If you want to hide the footer because the listview is empty just set
listview.footer = null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With