[英]How to Overlay Loading View for XAMARIN.FORMS
How to use overlay Activity indicator when select any list view. 选择任何列表视图时如何使用覆盖活动指示器。
<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>
Assuming you are not using MVVM (does not look like) and you are on a Page
it's fairly easy 假设您没有使用MVVM(看起来不像),并且您在Page
这相当简单
Put an ActivityIndicator
as well as the ListView
in an AbsoluteLayout
将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>
I've added an AbsoluteLayout
wrapping your ListView
. 我添加了一个包装您的ListView
的AbsoluteLayout
。 The ListView
is set up to take the whole area of the AbsoluteLayout
. ListView
设置为占据AbsoluteLayout
的整个区域。 Furthermore I've added an ActivityIndicator
on top, that is centered and has its default size ( AbsoluteLayout.LayoutFlags="PositionProportional"
and AbsoluteLayout.LayoutBounds=".5,.5,-1,-1"
). 此外,我在顶部添加了一个ActivityIndicator
,该指示器居中且具有默认大小( AbsoluteLayout.LayoutFlags="PositionProportional"
和AbsoluteLayout.LayoutBounds=".5,.5,-1,-1"
)。
As you can see here , Page
exposes the IsBusy
property, which you can set, when the page is busy, ie retrieving data or whatever. 如您在此处看到的,当页面忙时, Page
公开了IsBusy
属性,您可以设置该属性,即检索数据或其他内容。 I've bound the IsRunning
property of the ActivityIndicator
to IsBusy
, that the ActivityIndicator
shows up whenever the Page
indicates that it's busy. 我已经将ActivityIndicator
的IsRunning
属性绑定到IsBusy
,每当Page
指示忙时,该ActivityIndicator
显示出来。
From your code-behind, set IsBusy
for example from an async
method that retrieves your data 在您的后台代码中,例如从检索您的数据的async
方法中设置IsBusy
private async void Update()
{
IsBusy = true;
this.Data = await GetData();
IsBusy = false;
}
EDIT 编辑
Since you wanted to know, how to disable the ListView
in the background: 既然您想知道,如何在后台禁用ListView
:
You could overlay a tranparent BoxView
您可以叠加一个BoxView
<BoxView AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1"
BackgroundColor="Transparent"
InputTransparent="false"
IsVisible="{Binding Path=IsBusy, Source={x:Reference Page}}" />
Put this between your ListView
and your ActivityIndicator
and it should intercept all events the ListView
would receive otherwise. 将其放在ListView
和ActivityIndicator
,它应拦截ListView
否则会收到的所有事件。 Is is shown only when the ActivityIndicator
is shown. 仅在显示ActivityIndicator
显示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.