Pre loader

[cd]Using same instance of MVVM model for two charts causes unexpected behaviour


When trying to implement chart printing based on the xps example, I came across some wierd behaviour. In my scenario I’m using the same instance of the viewmodel as datacontext for the chart shown in GUI and the chart created in the CreateSciChartSurfaceWithoutShowingIt method. This causes the chart shown in the GUI to loose all it’s axis and datas. I have a suspicion this caused by the chart loosing it’s databining. In the attached example I have added to charts to the GUI and both are using the same instance of the viewmodel, to make it more clear. Only one chart works as expected. If trying to print to xps, both charts in the GUI looses their data. Please advice. Tnxs in advance. Keep up the good work

  • You must to post comments

Hi Oddvin,

This issues appears because of SeriesSource inner implementation. But there is simple workaround – you just need to use DataSet instead. Also, you need to comment out this row from CreateSciChartSurfaceWithoutShowingIt(…) method to prevent chart from disappearance after printing:

        private Visual CreateSciChartSurfaceWithoutShowingIt(Size size)
            // Create a fresh ChartView, this contains the ViewModel (declared in XAML) and data
            var control = new ChartView();
            var scs = control.SciChartSurface;

            //Comment out this line
            //scs.DataContext = this.customUserControl.SciChartSurface.DataContext;

Hope this helps! Please, let us know if you need any further assistance with this,

Best regards,

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies