我的app有这样的情况,当执行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;
}
我尝试了多种解决方案,但已经没有选择。有人可以指点我在正确的方向吗?
谢谢。