选择任何 ListView 时如何使用覆盖事件指示器。
<ListView x:Name="lstView" ItemsSource="{Binding Items}"
ItemTapped="Handle_ItemTapped"
ItemSelected="Handle_ItemSelected">
<ListView.Header>
<Label Text="Store Allocation" BackgroundColor="White" TextColor="Black" FontAttributes="Bold" HorizontalOptions="Fill" HorizontalTextAlignment="Center" />
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Title}" Height="200" Detail="{Binding Detail}" DetailColor="Black" TextColor="Red" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
最佳答案
假设您没有使用 MVVM(看起来不像)并且您使用的是 Page
这相当容易
输入 ActivityIndicator
以及 ListView
在 AbsoluteLayout
<ContentPage x:Name="Page" ...>
<AbsoluteLayout VerticalOptions="Fill">
<ListView AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
<!-- ... -->
</ListView>
<ActivityIndicator IsRunning="{Binding Path=IsBusy, Source={x:Reference Page}}" AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds=".5,.5,-1,-1" />
</AbsoluteLayout>
</ContentPage>
我添加了 AbsoluteLayout
包装您的ListView
。 ListView
设置为占据 AbsoluteLayout
的整个区域。此外,我还添加了 ActivityIndicator
在顶部,它居中并具有默认大小( AbsoluteLayout.LayoutFlags="PositionProportional"
和 AbsoluteLayout.LayoutBounds=".5,.5,-1,-1"
)。
如您所见here , Page
暴露IsBusy
属性,当页面繁忙时,您可以设置该属性,即检索数据或其他情况。我已经绑定(bind)了IsRunning
ActivityIndicator
的属性(property)至IsBusy
,即ActivityIndicator
每当 Page
时就会出现表示正忙。
从您的代码隐藏中,设置 IsBusy
例如来自async
检索您的数据的方法
private async void Update()
{
IsBusy = true;
this.Data = await GetData();
IsBusy = false;
}
编辑
既然你想知道如何禁用ListView
在后台:
您可以覆盖透明的 BoxView
<BoxView AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1"
BackgroundColor="Transparent"
InputTransparent="false"
IsVisible="{Binding Path=IsBusy, Source={x:Reference Page}}" />
将其放在您的 ListView
之间和你的ActivityIndicator
它应该拦截 ListView
的所有事件否则会收到。仅当 ActivityIndicator
时才显示显示。
关于c# - 如何覆盖 XAMARIN.FORMS 的加载 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48985304/