Issue with RadCartesianChart & Databinding on background threads

3 posts, 0 answers
  1. James
    James avatar
    2 posts
    Member since:
    Sep 2012

    Posted 26 Sep 2012 Link to this post

    I am databinding to a BarSeries for a RadCartesianChart on a background thread and I'm running into issues.  Specifically that none of my data is showing up.  If I bind the data on the main UI thread everything shows up great, but I need to bind the data in a callback from an asynchronous webservice call.  When I alter the BarSeries ItemSource in the callback, the RadCartesianChart never updates with the new information.

    Is there something I am doing wrong?  How can I bind data from an asynchronous web service call to a RadCartesianChart BarSeries?
  2. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 01 Oct 2012 Link to this post

    Hello James,

    The chart belongs to the UI thread and all actions that are done over it should be done from this thread. You can marshal to the UI thread using this code:

    p.Dispatcher.BeginInvoke(() => {
            p.Children.Clear();
            p.Children.Add(
                new TextBlock { Text = "Added by Dispatcher." });
        });

    More information is available here on MSDN.All the best,
    Yavor
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

  3. DevCraft banner
  4. James
    James avatar
    2 posts
    Member since:
    Sep 2012

    Posted 01 Oct 2012 Link to this post

    Thanks--I was already using the DIspatcher.  But I did manage to solve my problem--unsurprisingly it had nothing to do with the telerik control.  The problem was the data type I was using for the BasSeries.  Apparently you cannot add or remove items from a List in a background thread and expect the data binding to work properly, you have to use an ObservableColleciton.  So once I switched to an ObservableCollection I was fine.  I'm sure this is a dumb mistake but the List worked as long as the changes were done in the UI thread. 
Back to Top