How do you update a WPF chart when the collection changes? I am using WPF chart (System.Windows.Controls.DataVisualization.Toolkit.dllversion version 3.5.50211.1) to plot some simple data. The classes for the data look like this:
public class EngineMeasurementCollection : Collection<EngineMeasurement>
{
}
public class EngineMeasurement
{
public int TimeStamp { get; set;}
public int Speed { get; set; }
public int Torque { get; set; }
public int Power { get; set; }
}
In my Mainform, I am receiving new data on an event callback. This comes back on another thread. I look at the data to see if it has a new TimeStamp. If it is, I add it to my collection. I then dutifully call
Dispatcher.Invoke(myDelegate, DispatcherPriority.Normal,null)
to get myself back on the GUI thread. I then call:
m_ctrlLineSeriesTorque.ItemsSource = m_TorqueCollection;
to try and get the chart to update. I've verified I get into this code. I've also verified that I can display a chart if I just throw some values into the contructor of EngineMeasurementCollection. How do I get the chart to update as I add more values to the collection?
Somewhere I saw that there might be a "Refresh" method on the chart itself. I don't see that. Also, I saw that perhaps EngineMeasurementCollection should be an "Observable collection" and EngineMeasurement should implement some interface. True?
Thanks, Dave