0

在 Windows Phone 8 上工作。

遇到了一个问题,几年前我以某种方式解决了,但不记得了。

GetNews();
InitializeComponent();

private void GetNews()
{
    HttpWebRequest request = HttpWebRequest.CreateHttp(GS.BACKEND_HOST + "something");
    request.BeginGetResponse(new AsyncCallback(HandleResponseNews), request);
}

private void HandleResponseNews(IAsyncResult result)
{
    HttpWebRequest request = result.AsyncState as HttpWebRequest;
    if (request != null)
    {
        using (WebResponse response = request.EndGetResponse(result))
        {
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                string JSON = reader.ReadToEnd();
                NewsList = JsonConvert.DeserializeObject<News>(JSON) as News;
            }
        }
    }

}

我需要用 NewsList 项目填充我的列表框。但我只能在 NewsList 充满请求响应后才能做到。

我需要某种类型的触发器...

4

1 回答 1

-1

找到解决方案:

 Deployment.Current.Dispatcher.BeginInvoke(() => 
 { 
      foreach (Article article in NewsList.Result.Articles) 
      { 
      NewsListBox.Items.Add(article.Title); 
      } 
  }); 
于 2013-08-02T06:41:34.407 回答