簡體   English   中英

使用異步方法在Windows Phone 8.1中加載頁面

[英]Loading page in Windows Phone 8.1 with async method

當Windows Phone中的頁面正在加載時,我想顯示一個圓圈欄。 延遲歸因於異步方法,該方法會下載Json文件並將其協調到對象列表。 如果async方法在另一個Class中,這是一個問題嗎? 另外,如何在另一個類/頁面中獲取aysnc方法的結果?

在單獨的類中編寫代碼

public class Result 
{
   public string Message {get;set}
}
public class Utility
{
   public async Task<Result> GetJson()
   {
       //do something here
       return result;
   }
}

然后這樣稱呼它:

LoadingIndicator.Visibility = Visibility.Visible;
await Utility.GetJson()
LoadingIndicator.Visibility = Visibility.Collapsed;

並將其添加到您的頁面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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM