如何将ListView的页脚设置为IsVisible=false

3
这是页脚的XAML代码:
  <ListView.FooterTemplate IsVisible="{Binding IsLoading}">
    <DataTemplate>
      <StackLayout Padding="8">
        <Label Text ="Loading ..." 
               HorizontalOptions="CenterAndExpand"
               VerticalOptions="CenterAndExpand"/>
        <ActivityIndicator IsRunning="{Binding IsLoading}"                                                   
                Color="Blue" 
                HorizontalOptions="CenterAndExpand"
               VerticalOptions="CenterAndExpand"/>
      </StackLayout>
    </DataTemplate>        
  </ListView.FooterTemplate>
< p > 这个ActivityIndicator正常工作(当IsLoading设置为false时,它会停止)。但是我想让整个页脚在IsLoading设置为false时消失,但我做不到这一点。 < /p >

尝试传递一个可空的 IsLoading,一旦它被加载,将其设置为 null。 - Akash Kava
@AkashKava 当执行 PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 时(仅当 IsLoading 设置为 null 时),会抛出 System.NullReferenceException: Object reference not set to an instance of an object. - Xavier Peña
1个回答

0

您必须为 Footer 设置 BindingContext,并将 IsVisible 更改为 StackLayout

<ListView Footer="{Binding IsLoading}">     
    <ListView.FooterTemplate >
        <DataTemplate>
            <StackLayout IsVisible="{Binding .}" Padding="8">
                <Label Text="Loading ..." HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" />
                <ActivityIndicator IsRunning="{Binding .}" Color="Blue" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" />
            </StackLayout>
        </DataTemplate>
    </ListView.FooterTemplate>
</ListView>

1
我曾尝试过这样做。但是,如果我将IsVisible绑定到DataTemplate的子元素,它只会在列表底部留下一个空白空间。也就是说:原来由页脚使用的空间仍然存在,但其元素不再可见。 - Xavier Peña

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接