WPF 异步 httpclient 不返回字符串

WPF async httpclient not returning string

public RSS_Reader()
{
    this.InitializeComponent();
}

public static async Task<string> DownloadPageAsync(string pageURL)
{
    HttpClient client = new HttpClient();
    HttpResponseMessage response = await client.GetAsync("http://www.parliament.uk/g/RSS/news-feed/?pageInstanceId=209&limit=20");
    HttpContent content = response.Content;
    string result = await content.ReadAsStringAsync();
    return result;

}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    var parameter = e.Parameter as string;
    strURL = parameter.ToString();

    Task<string> strXML = DownloadPageAsync(strURL);

    ListBoxRss.Items.Add(strXML.Result);
 }

我一直在制作的 wp8 应用程序的一部分。应用程序的主登录页面链接到我从上面的代码中获取的第二页。第二页实际上从未加载,它只是挂在第一页上。

我做错了什么? 谢谢

您应该使 OnNavigatedTo 方法异步并等待 DownloadPageAsync 方法:

protected override async void OnNavigatedTo(NavigationEventArgs e)
{
    var parameter = e.Parameter as string;
    strURL = parameter.ToString();

    string strXML = await DownloadPageAsync(strURL);

    ListBoxRss.Items.Add(strXML);
}