如何在windows phone上发出json请求时显示加载消息

本文关键字:请求 json 显示 消息 加载 windows phone | 更新日期: 2023-09-27 18:25:37

当在windows phone上发出json请求时,我需要显示一条加载消息,就像在安卓系统上使用ProgressDialog的异步任务一样,我在onPreExecute()上放置dialog.show(),在onPostExecute上放置dialog.sdisse()。我怎么能在windows手机上做到这一点?

这是我的json请求:

WebClient webClient = new WebClient();
    webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
    webClient.DownloadStringAsync(new Uri("https://maps.googleapis.com/maps/api/place/textsearch/json?&query=taxi&location=-19.94549444,-43.92314218&&radius=5000&sensor=true&key=AIzaSyDucC8QBV5wu4V-dQXFfABXGaaUzdmT5xw"));

当这个请求正在下载时,我需要显示加载消息,并在请求完成时发送。

如何在windows phone上发出json请求时显示加载消息

您可以显示进度条来指示正在进行的进程
只需将代码如下:

WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
ProgressIndicator progressIndicator = new ProgressIndicator() {
    IsVisible = true,
    IsIndeterminate = false,
    Text = "Loading..." 
};
SystemTray.SetProgressIndicator(this, progressIndicator);
webClient.DownloadStringAsync(new Uri("https://maps.googleapis.com/maps/api/place/textsearch/json?&query=taxi&location=-19.94549444,-43.92314218&&radius=5000&sensor=true&key=AIzaSyDucC8QBV5wu4V-dQXFfABXGaaUzdmT5xw"));

当您的请求开始执行时,这将显示一个进度条
要在加载后停止此操作,请将以下代码添加到事件处理程序中:

void webClient_DownloadStringCompleted(s, e)
{
    Dispatcher.BeginInvoke( () =>
    {
        progressIndicator.IsVisible = false;
        // Your code
    });
}