[英]Loading page in Windows Phone 8.1 with async method
I want to display a loding circle bar, while a page in Windows Phone is loading. 当Windows Phone中的页面正在加载时,我想显示一个圆圈栏。 The latency is due to an async method, which donwloads a Json file and concert it to List of objects.
延迟归因于异步方法,该方法会下载Json文件并将其协调到对象列表。 Is it a problem, if the async method is in another Class ?
如果async方法在另一个Class中,这是一个问题吗? Also, how Can I get back the result of aysnc method in another class/page ?
另外,如何在另一个类/页面中获取aysnc方法的结果?
Write your code in separate class 在单独的类中编写代码
public class Result
{
public string Message {get;set}
}
public class Utility
{
public async Task<Result> GetJson()
{
//do something here
return result;
}
}
Then call it like this: 然后这样称呼它:
LoadingIndicator.Visibility = Visibility.Visible;
await Utility.GetJson()
LoadingIndicator.Visibility = Visibility.Collapsed;
And add this to your page XAML: 并将其添加到您的页面XAML:
<Grid>
<!-- Other UI elements -->
<StackPanel x:Name="LoadingIndicator" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="Collapsed">
<TextBlock Text="Loading..."/>
<ProgressRing IsActive="True" VerticalAlignment="Center"/>
</StackPanel>
</Grid>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.