title: How to properly handle data using asynchronous service with silverlight and telerik charts
body: <p>I have a silverlight application using telerik charts.</p>
  
  <p>In my view I have the chart in xaml.  In the code behind of the view I have something like this:</p>
  
  <pre><code>public partial class MyView : UserControl
  {
      private MyViewModel viewModel;
  
      public MyView()
      {
          InitializeComponent();
          CreateChartMappings();  // Creates the SeriesMappings for my chart
          viewModel = new MyViewModel();
          Chart1.ItemsSource = viewModel.MyChartData;
  
          DataContext = viewModel;
          Resources.Add("ViewModel", viewModel);
  
      }
  }
  </code></pre>
  
  <p>In my ViewModel I have this:</p>
  
  <pre><code>public class MyViewModel : INotifyPropertyChanged
  {
      private ObservableCollection&lt;ChartData&gt; myChartData;
      public ObservableCollection&lt;ChartData&gt; MyChartData
      {
          get { return myChartData; }
          set { myChartData= value; OnPropertyChanged("MyChartData"); }
      }
  
      public MyViewModel()
      {
          MyWebServiceClient service = MyWebServiceClient.CreateInstance();
  
          service.GetChartDataCompleted +=  
              new EventHandler&lt;GetChartDataCompletedEventArgs&gt;(GetChartDataCallback); 
  
          service.GetChartDataAsync();
      }
  
  
      private void GetChartDataCallback(object sender, GetChartDataCompletedEventArgs e)
      {
          if (e.Error == null)
          {
              MyChartData = e.Result;
          }
      }
  }
  </code></pre>
  
  <p>I know for sure that GetChartData will return the correctly typed data that can be used for the chart and see that GetChartDataCallback does return results in e.Result, but I don't know how to get that data loaded into my chart.</p>
  
  <p>If I do something like Chart1.ItemsSource = viewModel.MyChartData; after I am sure the service returns data then data loads into the chart fine.  For example, if I create a button in my view that calls that line of code it will load the data from the service into the chart.</p>
  
  <p>Also if I replace the asyc calls with a normal method call it will work okay as well, so my problem might have something to do with not handling the asyc call correctly?</p>