ArgumentException while binding

2 posts, 0 answers
  1. Petr
    Petr avatar
    1 posts
    Member since:
    Dec 2012

    Posted 21 Dec 2012 Link to this post


    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:ScatterLineSeries XValueBinding="Key"
                           ItemsSource="{Binding Path=DataSeries}">

    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;
  2. Petar Marchev
    Petar Marchev avatar
    1014 posts

    Posted 25 Dec 2012 Link to this post

    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.

Back to Top