Cannot cast from source type to destination type.

I'm having some troubles trying to initialize a variable always when I try to do it with the SfChart I get this error: "Cannot cast from source type to destination type."

This is my code: 

XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:syncfusion="clr-namespace:Syncfusion.SfChart.Android;assembly:Syncfusion.SfChart.Android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <com.syncfusion.charts.SfChart    
        android:id="@+id/chartWeeklyResult"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">
</com.syncfusion.charts.SfChart>
</LinearLayout>

C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Com.Syncfusion.Charts;
using Com.Syncfusion.Charts.Enums;
using Android.Graphics;

namespace Stop_Diabetes_Android
{
[Activity (Label = "Statistics")]
public class StatisticsActivity : Activity
{
private SfChart chartIn;

protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView(Resource.Layout.Statistics);

try{
chartIn = (SfChart) FindViewById (Resource.Id.chartWeeklyResult);

}
catch (Exception ex) {
}
}
}
}

I'd like to know if someone know how to fix it. Thanks for your worthy time and help.

1 Reply

YP Yuvaraj Palanisamy Syncfusion Team September 7, 2015 05:19 AM UTC

Hi Federico,

Thanks for using Syncfusion products.

Please use the following code example to get the chart reference from layout.

Code Example [C#]

chartln = FindViewById<SfChart>(Resource.Id.chartWeeklyResult);



Regards,
Yuvaraj

Loader.
Up arrow icon