有没有一种方法可以根据运行时的条件动态显示/隐藏 ListView 的标题。
<ListView x:Name="ListViewChallenges" Header="{Binding .}">
<ListView.FooterTemplate>
<DataTemplate>
<Label Text="No Elements found." IsVisible="{Binding FooterIsVisible}" />
</DataTemplate>
</ListView.FooterTemplate>
<!-- ... -->
</ListView>
在 BindingContext 中,我声明了 FooterIsVisible 属性。当为 false 时,页脚应该是不可见的。然而这不起作用,页脚总是为 ListView 底部的标签占用一定的空间。
这有可能吗?
最佳答案
您应该能够隐藏页脚并且不让它占用任何空间。我相信您需要在 FooterTemplate
中设置标签的 HeightRequest
。您可以通过执行以下操作来做到这一点:
<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>
关于listview - 动态显示/隐藏 Xamarin.Forms.ListView 的页眉或页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41895092/