We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Binding SfChart Series Property

Hello,

I'm using Xamarin Forms and building MVVM based application. I want my ViewModel to take care of number and type of series in chart, so I am trying to bind Series Property:

Chart.SetBinding(SfChart.SeriesProperty, "DataCollection"BindingMode.OneWay);
where DataCollection is defined in ViewModel:
private ChartSeriesCollection _dataCollection = new ChartSeriesCollection();
public ChartSeriesCollection DataCollection
        {
            get { return _dataCollection; }
            set
            {
                _dataCollection = value;
                OnPropertyChanged();
            }
        }
But using binding this way gives me error:

System.NullReferenceException: Object reference not set to an instance of an object.

Other bindings work all right.
Why can't I bind SeriesProperty to ChartSeriesCollection?

3 Replies

YP Yuvaraj Palanisamy Syncfusion Team January 12, 2017 01:00 PM UTC

Hi Boris,

Thanks for contacting Syncfusion support.

We are unable to reproduce the issue at our end. Also, we had prepared a sample and attached for your reference. Please check whether you are able to reproduce the reported issue in this sample. If not, please update us the modified sample to reproduce the issue for providing further assistance.

Sample: http://www.syncfusion.com/downloads/support/forum/128268/ze/ChartSample990987186  

Please let us know if you have any concerns.

Regards,
Yuvaraj 



BO Boris January 25, 2017 10:47 AM UTC

Thank you for your answer. Your example indeed works well. I found out problem was with Xamarin's binding context. I am using Prism framework and it automatically sets BindingContext of View. Problematic page had SfChart inside 3 containers (SfNavigationDrawer, ScrollView, StackLayout) so on the way BindingContext had been lost. I fixed the problem with
Chart.BindingContext = BindingContext;

And now everything works. Views that werent so deep inside containers were binding with no problems and had right binding context.


MK Magesh Kumar Krishnan Syncfusion Team January 26, 2017 12:19 PM UTC

Hi Boris,

We are glad that your issue has been fixed.
Please let us know if you need any other assistance.

Regards,
Magesh




Loader.
Up arrow icon