【问题标题】:How to set ListView footer to IsVisible=false如何将 ListView 页脚设置为 IsVisible=false
【发布时间】:2016-07-04 16:03:32
【问题描述】:

这是页脚的 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>

ActivityIndicator 正在按预期工作(当IsLoading 设置为false 时它会停止)。但是一旦IsLoading 设置为false,我想让整个页脚消失,​​我无法做到这一点。

【问题讨论】:

  • 尝试传递一个可以为空的IsLoading,一旦加载,设置为null
  • @AkashKava 在执行PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 时会抛出System.NullReferenceException: Object reference not set to an instance of an object.(就在IsLoading 设置为null 时)。

标签: c# xaml xamarin


【解决方案1】:

您必须为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>

【讨论】:

  • 我曾尝试过这样做。但是,如果我将 IsVisible 绑定到 DataTemplate 的子元素,它只会在列表底部留下一个空白区域。即:页脚之前使用的空间仍然存在,但其元素不再可见
猜你喜欢
  • 2016-06-13
  • 2012-01-02
  • 2012-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-26
  • 2015-10-25
相关资源
最近更新 更多