2013-07-31 14 views
3

我需要顯示一個加載消息,同時在Windows Phone上發出json請求,就像使用Android上的ProgressDialog進行異步任務,在onPreExecute()和dialog.dismiss()上放置dialog.show() onPostExecute。我怎樣才能在Windows Phone上做到這一點?如何在windows phone上發出json請求時顯示加載消息?

這裏是我的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")); 

雖然這個請求被下載,我需要顯示加載消息,耳鼻喉科它的請求完成時。

+0

在刪除後的解決方案不起作用? –

+1

它不起作用。 –

+0

對我來說也不行。 – Gavjr

回答

3

您可以顯示進度條來指示正在進行的過程。
只要把代碼如下:

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 
    }); 
} 
+0

它的工作原理!真的感謝! –

+0

@DanielNazareth:Pleasure :) –

+0

如何將此加載放置在屏幕中央? – Krunal

相關問題