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
close icon

GalaSoft data binding

Hi,

try to bind the ItemsSource of a BarSeries to a collection of my ViewModel. I have the following code:

_barSeries = new BarSeries {
    ListenPropertyChange = true,
    XBindingPath = nameof(ChartData.Name),
    YBindingPath = nameof(ChartData.Value),
    TooltipEnabled = true,
    EnableAnimation = true,
    AnimationDuration = 0.8
};
_chartView.Series.Add(_barSeries);

var test = this.SetBinding(() => ViewModel.ChartCollection, () => _barSeries.ItemsSource);
But the chartview doesn't show anything. Is it possible to do a data binding with Xamarin.Android SfChart? Any suggestions? Thank you.

3 Replies

RA Rachel A Syncfusion Team July 2, 2019 05:19 AM UTC

Hi Markus, 
 
Thanks for contacting Syncfusion Support. 
 
We have analyzed your code snippet and tried to bind the ItemSource of a BarSeries to a collection of ViewModel. But we are unable to bind the ItemSource property as it is of type IEnumerable. So, we have achieved your requirement by creating a custom class inheriting BarSeries and creating a property of type ObservableCollection and binding that property to ViewModel collection. We have attached the sample for your reference, and it can be downloaded from the below link. 
 
 
Code snippet [C#] - BarSeriesExt 
public class BarseriesExt : BarSeries 
{ 
    private ObservableCollection<ChartData> data; 
    public ObservableCollection<ChartData> Data 
    { 
        get { return data; } 
        set 
        { 
            if (data != value) 
            { 
                data = value; 
                ItemsSource = data; 
            } 
        } 
    } 
} 
 
Code snippet [C#] – MainActivity.cs 
this.SetBinding(() => Vm.BarData, () => Series.Data); 
 
Please let us know if you have any concerns. 
 
Regards, 
Rachel. 
 



MA Markus July 2, 2019 06:21 AM UTC

Thank you, for your reply. With this hint, I can add my bindings.


RA Rachel A Syncfusion Team July 2, 2019 06:30 AM UTC

Hi Markus, 
 
Thanks for the update. 
 
Please revert to us if you have any queries. 
 
Thanks, 
Rachel. 


Loader.
Live Chat Icon For mobile
Up arrow icon