【问题标题】:Windows Phone 8 ProgressBar incorrectly displaying with ListBoxWindows Phone 8 ProgressBar 与 ListBox 一起显示不正确
【发布时间】:2016-03-29 01:12:54
【问题描述】:

我的应用程序出现这样的情况,即在执行 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;
}

我尝试了多种解决方案,但都没有选择。有人可以在这里指出我正确的方向吗?

谢谢。

【问题讨论】:

    标签: c# xaml windows-phone-8


    【解决方案1】:

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

    您可能想查看thisthis

    要获得更简洁的代码,请尝试绑定进度条可见性,例如 this onethis

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多