动态显示/隐藏Xamarin.Forms.ListView的页眉或页脚 [英] Dynamically show/hide Header or Footer of Xamarin.Forms.ListView

查看:287
本文介绍了动态显示/隐藏Xamarin.Forms.ListView的页眉或页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以根据运行时的条件动态显示/隐藏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>

在BindingContext中,我声明了FooterIsVisible属性.如果为假,则页脚应该是不可见的.但是,这不起作用,页脚始终在ListView底部占用Label的特定空间.

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.

这有可能吗?

推荐答案

您应该能够隐藏页脚,并且不占用任何空间.我相信您需要为FooterTemplate中的标签设置HeightRequest.您可以通过执行以下操作来做到这一点:

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>

这篇关于动态显示/隐藏Xamarin.Forms.ListView的页眉或页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆