SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components
Unless I put in a large delay on construction of my base class, I get an exception “Object reference not set to an instance of an object” on calling
_sciChartEventAggregator = numericAxis.Services.GetService();
Please could you tell me what is going on? I can send you an example in my product, but as this is confidential, I cannot post the example on the forum. If the example will help please tell me how I can send it to you
Thanks
Hi there,
AxisBase.Services property is initialized when an axis is attached to SciChartSurface instance. So please check if you access it after that. Also be aware, that this call is equal to SciChartSurface.Services.GetService(), as axes share same Services instance as their parent surface.
Please, let us know if this info helps you to solve the issue.
Best regards,
Yuriy
Hi there,
We’ve investigated the issue. Exception is thrown because your axes collection haven’t been attached to the surface yet. You can easily prevent it by this check:
if(numericAxis.ParentSurface != null) { _sciChartEventAggregator = numericAxis.Services.GetService(); }
How to know when you can get it? Well, you could consider listening to AxisBase.PropertyChanged. Something like that:
numericAxis.PropertyChanged = OnAxisPropertyChanged; .... private void OnAxisPropertyChanged(object sender, PropertyChangedEventArgs e) { var numericAxis = sender as IAxis; if(e.PropertyName=="ParentSurface") { if(numericAxis.ParentSurface != null) { _sciChartEventAggregator = numericAxis.Services.GetService(); } } }
Please, don’t hesitate to ask if you have any questions,
Best regards,
Yuriy
_sciChartEventAggregator.Publish(new ZoomExtentsMessage(this));with one of – call dataSeries.InvalidateParentSurface(RangeMode.ZoomToFit) or RangeMode.ZoomToFitY – pass the chart’s ZoomExtents command to the ViewModel through binding and call Execute() wherever you need in the VM – inject the SciChartSurface as IInvalidatable to the ViewModel (you could take a look at this MiVVM pattern article) and remove the _sciChartEventAggregator? I tried using dataSeries.InvalidateParentSurface(RangeMode.ZoomToFit); but get Error 33 'Abt.Controls.SciChart.XyDataSeries' does not contain a definition for 'InvalidateParentSurface' and no extension method 'InvalidateParentSurface' accepting a first argument of type 'Abt.Controls.SciChart.XyDataSeries' could be found (are you missing a using directive or an assembly reference?) C:\QNX630\CSharp\AVRHMI\src\AVR_HMI\ViewModels\BaseAnalogueChartViewModel.cs 1231 24 AVR_HMI
Please login first to submit.