簡體   English   中英

Windows Phone 8 ProgressBar與ListBox錯誤地顯示

[英]Windows Phone 8 ProgressBar incorrectly displaying with ListBox

我的應用程序遇到一種情況,當執行OnNavigatedTo時ProgressBar可以正確顯示。 然后,在搜索和整理重新獲得的數據的過程中,ProgressBar會掛起/凍結。 最后,當所有數據均已收集並正確顯示在列表中后,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;
}

我嘗試了多種解決方案,但用完了所有選項。 有人可以在這里指示我正確的方向嗎?

謝謝。

這是與異步方法有關的問題,因為它們凍結UI(按照我的想法)直到執行完成。

您可能想看看這個以及這個

對於一個更干凈的代碼,嘗試結合樣的進度條可見這個這個

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM