在 Xamarin Forms 中加载页面时显示文本 [英] Display text while Page is loading in Xamarin Forms

查看:35
本文介绍了在 Xamarin Forms 中加载页面时显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很重的页面,点击后加载了大约 1-2 秒.在这段时间里,我看到正在加载页面标题和旧页面内容,它看起来反应迟钝.我想要实现的只是显示带有正在加载..."或活动指示器等内容的临时标签,只要正在加载新页面,但我不知道如何执行此操作.实现这一目标的更好方法是什么?提前致谢

I have a page that is quite heavy and its loading for about 1-2 sec after click. During this time I see loading page header and old page content, it looks so irresponsive. All I want to achive is to display temporary Label with content like "Loading..." or activityindicator as long as new page is loading but I have no idea how to do this. What is the better way to achive this? Thanks in advance

推荐答案

根据您的评论,您只想在从 Api 加载数据时显示 Busy 指示器.您没有发布您的用户界面,但我希望您了解如何使用以下内容:

Based on your comments, you just want to display Busy indicator while you are loading the Data from your Api. You didn't posted your UI but I hope you understand how to use the below:

<Grid>
     <YOUR-UI>
         .....
         .........
     </YOUR-UI>

     <ActivityIndicator VerticalOptions="Center" IsVisible="{Binding IsBusy}" IsRunning="{Binding IsBusy}"/>
</Grid>

在您的 ViewModel 中,添加 IsBusy 属性如下:

In your ViewModel, Add IsBusy Property as below:

private bool _isBusy;
public bool IsBusy
{
    get{return _isBusy;}
    set { _isBusy=value; RaisePropertyChanged(); }
}

然后,当您调用 API 加载数据时,请执行以下操作:

Then when you are Calling the API to load your Data do something like:

public async void LoadDataFromApi()
{
    IsBusy=true;  //Show the Indicator
    var response= await YourService.Method();  //this is where you calling your api
    //do other stuffs if you need to do;
    IsBusy=false;   //Hide the Indicator
}

如果您需要更多帮助,请告诉我.

Let me know if you need anymore help.

这篇关于在 Xamarin Forms 中加载页面时显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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