2016-03-28 46 views
0

我有我的應用程序的情況,即在執行OnNavigatedTo時ProgressBar正確顯示。然後,在搜索和整理已重新發送的數據的過程中,ProgressBar掛起/凍結。最後,當所有數據已被收集並正確顯示在列表中時,ProgressBar會正確摺疊。Windows Phone 8的ProgressBar與列表框錯誤地顯示

我的XAML看起來像這樣:

<ProgressBar 
    x:Name="progressbar" 
    IsIndeterminate="True" 
    Minimum="0" 
    Maximum="100" 
    Value="0" 
    Width="400" 
    Height="30" 
    Foreground="#FF117B0F" 
/> 

我的C#是這樣的:

List<GameLive> gameLive; 

public MainPage() 
{ 
    InitializeComponent(); 
    gameLive = new List<GameLive>(); 
    ProgressBar progressbar = new ProgressBar(); 
} 

protected async override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    base.OnNavigatedTo(e); 
    string htmlPageLive = ""; 
    bool isError = false; 

    HttpClient client = new HttpClient(); 

    try 
    { 
     htmlPageLive = await client.GetStringAsync("webpage"); 
    } 

    catch (Exception) 
    { 
     isError = true; 
    } 

    if (isError) 
    { 
     MessageBox.Show("Unable to retrieve data"); 
     return; 
    } 

    HtmlDocument htmlDocumentLive = new HtmlDocument(); 
    htmlDocumentLive.LoadHtml(htmlPageLive); 

    foreach (var div in htmlDocumentLive.DocumentNode.SelectNodes("..nav..")) 
    { 
     bool isErrorTwo = false; 
     GameLive newGame = new GameLive(); 
     try 
     { 
      newGame.Title = removed; 
      newGame.Summary = removed; 

      gameLive.Add(newGame); 
     } 

     catch (Exception) 
     { 
      isErrorTwo = true; 
     } 

     if (isErrorTwo) 
     { 
      NavigationService.Navigate(new Uri("/Temp.xaml", UriKind.Relative)); 
      return; 
     } 
    } 
     lstGameLive.ItemsSource = gameLive; 
     progressbar.Visibility = Visibility.Collapsed; 
     progressbar.IsIndeterminate = false; 
} 

我嘗試過多種解決方案,但已用完的選項。有人可以在這裏指出我正確的方向嗎?

謝謝。

回答

0

這是一個與異步方法有關的問題,因爲它們會凍結UI(我認爲),直到執行完成。

你可能想看看thisthis

一個更加乾淨的代碼,嘗試結合樣this onethis

進度條可見