Search code examples
c#androidxamarin.formsmvvmcrosssyncfusion

(Syncfusion) After SfChart recieves the second Data Object via Data Binding I get an ERROR: System.NullReferenceException


I have a MVVMCross application (Android only at the Moment) and I am using Syncfusion to present some data. The Data Class has a DateTime Property and a double Property. The Data Class recieves it's values correctly and adds them in a list where the view can access them via DataBinding. The View and the Chart with the DataBinding Looks like this:

 <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                <sfChart:SfChart HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" >

                    <sfChart:SfChart.Legend>
                        <sfChart:ChartLegend />
                    </sfChart:SfChart.Legend>

                    <sfChart:SfChart.Title>
                        <sfChart:ChartTitle Text="Daten lesen" />
                    </sfChart:SfChart.Title>

                    <sfChart:SfChart.PrimaryAxis>
                        <sfChart:DateTimeAxis>
                            <sfChart:DateTimeAxis.Title>
                                <sfChart:ChartAxisTitle Text="Zeitpunkt" />
                            </sfChart:DateTimeAxis.Title>
                        </sfChart:DateTimeAxis>
                    </sfChart:SfChart.PrimaryAxis>

                    <sfChart:SfChart.SecondaryAxis>
                        <sfChart:NumericalAxis>
                            <sfChart:NumericalAxis.Title>
                                <sfChart:ChartAxisTitle Text="Wert" />
                            </sfChart:NumericalAxis.Title>
                        </sfChart:NumericalAxis>
                    </sfChart:SfChart.SecondaryAxis>

                    <sfChart:SfChart.Series>
                        <sfChart:LineSeries ItemsSource="{Binding ChartCurrentData.ChartDataLog}" XBindingPath="DateTimeValue" YBindingPath="Value">
                        </sfChart:LineSeries>
                    </sfChart:SfChart.Series>
                </sfChart:SfChart>
            </StackLayout>

The Data is represented in the ViewModel in this Property:

private ChartData _chartCurrentData;
 public ChartData ChartCurrentData { get { return _chartCurrentData; } set { _chartCurrentData = value; RaisePropertyChanged(() => ChartCurrentData); } }

ChartData is a class that stores a list of DataLog (ChartDataLog) which has 2 Properties: DateTime DateTimeValue and double Value.

The Chart itself is getting displayed just fine when I access it and after the first value gets sent in via Eventhandler and MvxNotifyProprtyChanged's help the Chart Axis for the value adapts to the Right range (as well as the Date) but as soon as the second value get's sent in the following error appears:

Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
 at Mono.Debugging.VisualStudio.ExceptionsAdapter.OnUnhandledException(Object sender, TargetEventArgs args) in E:\A_work\2239\s\src\Debugging.VisualStudio.Vsix\Integration\ExceptionsAdapter.cs:line 71
 at Mono.Debugging.Client.DebuggerSession.OnTargetEvent(TargetEventArgs args) in E:\A_work\2239\s\external\debugger-libs\Mono.Debugging\Mono.Debugging.Client\DebuggerSession.cs:line 1143
 at Mono.Debugging.Soft.SoftDebuggerSession.HandleBreakEventSet(Event[] es, Boolean dequeuing) in E:\A_work\2239\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerSession.cs:line 1906
 at Mono.Debugging.Soft.SoftDebuggerSession.HandleEventSet(EventSet es) in E:\A_work\2239\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerSession.cs:line 1589
 at Mono.Debugging.Soft.SoftDebuggerSession.EventHandler() in E:\A_work\2239\s\external\debugger-libs\Mono.Debugging.Soft\SoftDebuggerSession.cs:line 1489

I've tried many Things already so I don't even know where to start so any advice thoughts on this would already be help enough =) Thanks in advance


Solution

  • Figured it out. Had to add it via UI-Thread...