C# Windows Phone 8进度条与列表框不正确显示

C# Windows Phone 8进度条与列表框不正确显示,c#,xaml,windows-phone-8,C#,Xaml,Windows Phone 8,我的应用程序存在这样一种情况:执行OnNavigatedTo时,ProgressBar会正确显示。然后,在搜索和整理重新提交的数据的过程中,ProgressBar将挂起/冻结。最后,当所有数据都已收集并正确显示在列表中时,ProgressBar将正确折叠 我的XAML如下所示: <ProgressBar x:Name="progressbar" IsIndeterminate="True" Minimum="0" Maximum="100" Valu

我的应用程序存在这样一种情况:执行OnNavigatedTo时,ProgressBar会正确显示。然后,在搜索和整理重新提交的数据的过程中,ProgressBar将挂起/冻结。最后,当所有数据都已收集并正确显示在列表中时,ProgressBar将正确折叠

我的XAML如下所示:

<ProgressBar
    x:Name="progressbar"
    IsIndeterminate="True"
    Minimum="0"
    Maximum="100"
    Value="0"
    Width="400"
    Height="30"
    Foreground="#FF117B0F"
/>
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;
}

我的C#看起来像这样:

<ProgressBar
    x:Name="progressbar"
    IsIndeterminate="True"
    Minimum="0"
    Maximum="100"
    Value="0"
    Width="400"
    Height="30"
    Foreground="#FF117B0F"
/>
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;
}
List gameLive;
公共主页()
{
初始化组件();
gameLive=新列表();
ProgressBar ProgressBar=新的ProgressBar();
}
受保护的异步重写无效OnNavigatedTo(NavigationEventArgs e)
{
基地。导航到(e);
字符串htmlagelive=“”;
bool-isError=false;
HttpClient=新的HttpClient();
尝试
{
htmlagelive=await client.GetStringAsync(“网页”);
}
捕获(例外)
{
isError=真;
}
如果(isError)
{
MessageBox.Show(“无法检索数据”);
返回;
}
HtmlDocument htmlDocumentLive=新HtmlDocument();
htmlDocumentLive.LoadHtml(htmlagelive);
foreach(htmlDocumentLive.DocumentNode.SelectNodes(“…nav…”)中的var div)
{
bool-isErrorTwo=false;
GameLive newGame=newgamelive();
尝试
{
newGame.Title=已删除;
newGame.Summary=已删除;
gameLive.Add(新游戏);
}
捕获(例外)
{
ISERRORTOW=真;
}
如果(两个)
{
NavigationService.Navigate(新Uri(“/Temp.xaml”,UriKind.Relative));
返回;
}
}
lstGameLive.ItemsSource=gameLive;
progressbar.Visibility=Visibility.collazed;
progressbar.IsIndeterminate=false;
}
我尝试了多种解决方案,但没有选择。谁能给我指一下正确的方向吗


谢谢。

这是一个与异步方法相关的问题,因为它们冻结UI(我认为)直到执行完成

你可能还想看看

要获得更清晰的代码,请尝试绑定进度条可见性,如和