Question

Working on Windows Phone 8.

Have run into a problem that i somehow solved few years ago, but can't remember.

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;
            }
        }
    }

}

I need to fill my listbox with NewsList items. But i can make it only after NewsList is filled with request response.

I need some type of trigger...

Was it helpful?

Solution

Found solution:

 Deployment.Current.Dispatcher.BeginInvoke(() => 
 { 
      foreach (Article article in NewsList.Result.Articles) 
      { 
      NewsListBox.Items.Add(article.Title); 
      } 
  }); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top