I have two similar charts, the first one is rendered in the View and it is working fine, but the other one is rendered in the memory at run time. The both charts share the same RenderableSeries, but when I assign the RenderableSeries to the SciChartSurface Instance at run time then I get the following error message:
Cannot implicitly convert type ‘System.Collections.ObjectModel.ObservableCollection(SciChart.Charting.Model.ChartSeries.ImpulseRenderableSeriesViewModel)’ to ‘System.Collections.ObjectModel.ObservableCollection(SciChart.Charting.Visuals.RenderableSeries.IRenderableSeries)’
I already changed the Data Type of the renderable Series to FastImpulseRenderableSeries but the behavior in the View is not the same.
I am trying to cast each serie but it does not work. do you habe a hint for me?
- Developer PFH asked 8 years ago
- You must login to post comments
Thanks a lot. It works perfectly now.
- Developer PFH answered 8 years ago
- You must login to post comments
Hi there,
You cannot cast IRenderableSeriesViewModel to IRenderableSeries – they are different types (please see our Class Hierarchy, you can see what inherits what).
Instead, you need to convert RenderableSeriesViewModels to RenderableSeries. The way we do this in WPF is via the SeriesBinding MarkupExtension:
<!-- VIEW-->
<!-- Declare a SciChartSurface with SeriesBinding -->
<!-- Where xmlns:s="http://schemas.abtsoftware.co.uk/scichart -->
<s:SciChartSurface RenderableSeries="{s:SeriesBinding RenderableSeriesViewModels}">
<!-- XAxis, YAxis omitted for brevity -->
</s:SciChartSurface>
// Viewmodel
private ObservableCollection<IRenderableSeriesViewModel> _renderSeriesViewModels;
public ObservableCollection<IRenderableSeriesViewModel> RenderableSeriesViewModels
{
get { return _renderSeriesViewModels; }
set
{
_renderSeriesViewModels = value;
OnPropertyChanged("RenderableSeriesViewModels");
}
}
The equivalent in C# code only is to use a converter, e.g.
List<IRenderableSeriesViewModel> rSeriesViewModels = ... // populate your view models
var sciChartSurface = new SciChartSurface();
sciChartSurface.RenderableSeries = new RenderableSeriesSourceCollection(rSeriesViewModels);
Best regards,
Andrew
- Andrew Burnett-Thompson answered 8 years ago
- You must login to post comments
Please login first to submit.