- Home
- Forum
- Xamarin.Android
- GalaSoft data binding
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.
SIGN IN To post a reply.
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.
Sample - https://www.syncfusion.com/downloads/support/directtrac/145567/ze/145567_data_binding2180709.zip
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.
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
MA Markus
- Jun 28, 2019 07:22 AM UTC
- Jul 2, 2019 06:30 AM UTC