This is a migrated thread and some comments may be shown as answers.

ArgumentException while binding

1 Answer 126 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Petr
Top achievements
Rank 1
Petr asked on 21 Dec 2012, 09:42 AM
Hey,

I am evaluating the telerik chart component (trial version) for its suitability for our software project, and can not bring the RadCartesianChart to work.  

I am trying to put a new view atop of an existing viewmodel, and bind the chart data to a property of type ObeservableCollection<KeyValuePair<int, double>>. When the collection is empty its ok, but when trying to populate it, I get
ArgumentException: Dynamic getter is not supported for value types. 

Any idea why this happens and what the solution is? 

My code: View:
<telerik:RadCartesianChart Grid.Row="1">
            <telerik:RadCartesianChart.HorizontalAxis>
                <telerik:LinearAxis/>
            </telerik:RadCartesianChart.HorizontalAxis>
 
            <telerik:RadCartesianChart.VerticalAxis>
                <telerik:LinearAxis/>
            </telerik:RadCartesianChart.VerticalAxis>
 
            <telerik:RadCartesianChart.Series>
                <telerik:ScatterLineSeries XValueBinding="Key"
                       YValueBinding="Value"
                       ItemsSource="{Binding Path=DataSeries}">
 
                </telerik:ScatterLineSeries>
            </telerik:RadCartesianChart.Series>
 
        </telerik:RadCartesianChart>

And the view model:
// populated in Constructor
       private ObservableCollection<KeyValuePair<int, double>> mTempRandomData = new ObservableCollection<KeyValuePair<int, double>>();       
 
       private ObservableCollection < KeyValuePair <int, double> > mDataSeries = new ObservableCollection < KeyValuePair < int, double > > ();
 
        public ObservableCollection<KeyValuePair<int, double>> DataSeries
        {
            get { return mDataSeries; }
            set { mDataSeries = value; RaisePropertyChanged ( ()=>DataSeries );
            }
        }
 
        private void DoResetData ( )
        {
            DataSeries = new ObservableCollection < KeyValuePair < int, double > > ();
        }
        private void DoAddRandomData()
        {
            DoResetData (  );            
            DataSeries = mTempRandomData;
             
        }

1 Answer, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 25 Dec 2012, 07:11 AM
Hello Petr,

When creating the XValueBinding (and the other bindings) in XAML, the parser creates a PropertyNameDataPointBinding and sets it to the XValueBinding (help topic here). This type of binding can only work with reference types and not with value types. Since the KeyValuePair is a struct - the chart cannot work with it, thus the exception is thrown.

You can use another type of DataPointBinding we have  - the GenericDataPointBinding. This is how you can use it:
var dpb = new GenericDataPointBinding<KeyValuePair<int, double>, int>();
dpb.ValueSelector = pair => pair.Key;
 
scatterSeries.XValueBinding = dpb;

Do try this and see how it goes. Let us know if you need further assistance.

Kind regards,
Petar Marchev
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ChartView
Asked by
Petr
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Share this question
or