So, I'd like to bind the data source of a LineGraph to a CompositeDataSource in a wpf app with MVVM pattern. Here is what I've done so far:
The relevant line in the XAML:
<d3:LineGraph DataSource="{Binding signal}" Stroke="Blue"/>
signal is my CompositeDataSource object.
Relevant part of my ViewModel:
private void LoadSignalExecuted()
{
OnLoadSignal();
plotter.CreateGraph(dataFile);
signal = plotter.ECGData;
OnPropertyChanged("signal");
}
OnLoadSignal() does nothing important in this case. plotter is a class in my Model namespace. The CreateGraph(dataFile) does nothing else but populates a
public List<Points> Values { get; private set; }
object. It's populated correctly, I checked. My Points class is the following:
class Points
{
public Double X { get; set; }
public Double Y { get; set; }
public Points(Double xData, Double yData)
{
X = xData;
Y = yData;
}
}
plotter.ECGData looks like this:
public CompositeDataSource ECGData
{
get
{
var xData = new EnumerableDataSource<double>(Values.Select(v => v.X));
xData.SetXMapping(x => x);
var yData = new EnumerableDataSource<double>(Values.Select(v => v.Y));
yData.SetYMapping(y => y);
_data = xData.Join(yData);
return _data;
}
}
Where _data is a CompositeDataSource of course.
I figured this would work but the LineGraph doesn't appear upon OnPropertyChanged("signal"), which is implemented correctly I'm positive about that. VS Output Box says:
System.Windows.Data Error: 40 : BindingExpression path error: 'signal' property not found on 'object' ''ECGViewModel' (HashCode=41182536)'. BindingExpression:Path=signal; DataItem='ECGViewModel' (HashCode=41182536); target element is 'LineGraph' (Name=''); target property is 'DataSource' (type 'IPointDataSource')
Can someone point out the mistake here? Thanks!
Is ECGViewModel
in a different project? Have you tried a full rebuild? Perhaps you have an old version of ECGViewModel
around that actually doesn't have the signal property on it.