【发布时间】: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