Dynamic getter is not supported for value type [KeyValuePair`2]

2 posts, 0 answers
  1. StepTNT
    StepTNT avatar
    18 posts
    Member since:
    Mar 2013

    Posted 26 Oct 2014 Link to this post

    Hi there,
    I'm trying the new Universal UI and I ran in this exception when binding to an ObservableDictionary<string, int>

    System.ArgumentException:
    Dynamic getter is not supported for value type [KeyValuePair`2]   at
    Telerik.Universal.Core.DynamicHelper.CreatePropertyValueGetter(Type
    type, String propertyName)   at
    Telerik.Universal.UI.Xaml.Controls.Chart.PropertyNameDataPointBinding.GetValue(Object
    instance)   at
    Telerik.Universal.UI.Xaml.Controls.Chart.CategoricalSeriesDataSource.InitializeBinding(DataPointBindingEntry
    binding)   at
    Telerik.Universal.UI.Xaml.Controls.Chart.ChartSeriesDataSource.GenerateDataPoint(ObjeHere's the code that I'm using:

    01.public ObservableDictionary<string, int> MyDict { get; set; }
    02....
    03.private void UpdateStats()
    04.{
    05.    MyDict.Clear();           
    06.    foreach (var item in Items)
    07.    {
    08.        var dayString = item.When.Date.ToLocalTime().ToString();
    09.        var dayKey = dayString.Split(' ')[0];
    10.        MyDict[dayKey] = (MyDict.ContainsKey(dayKey)) ? MyDict[dayKey] + 1 : 1;               
    11.    }
    12.}


    01.<chart:RadCartesianChart x:Name="lineSeries"
    02.                         PaletteName="DefaultLight"
    03.                         ClipToBounds="False">
    04.    <chart:RadCartesianChart.VerticalAxis>
    05.        <chart:LinearAxis/>
    06.    </chart:RadCartesianChart.VerticalAxis>
    07.    <chart:RadCartesianChart.HorizontalAxis>
    08.        <chart:CategoricalAxis AutoGroup="True"
    09.                               PlotMode="OnTicks"/>
    10.    </chart:RadCartesianChart.HorizontalAxis>
    11.    <chart:LineSeries ItemsSource="{Binding AsthmaStats}">
    12.        <chart:LineSeries.CategoryBinding>
    13.            <chart:PropertyNameDataPointBinding PropertyName="Key"/>
    14.        </chart:LineSeries.CategoryBinding>
    15.        <chart:LineSeries.ValueBinding>
    16.            <chart:PropertyNameDataPointBinding PropertyName="Value"/>
    17.        </chart:LineSeries.ValueBinding>
    18.    </chart:LineSeries>
    19.</chart:RadCartesianChart>


    What's wrong with it?
  2. Vladislav
    Admin
    Vladislav avatar
    276 posts

    Posted 29 Oct 2014 Link to this post

    Hi Stefano Tenuta,

    currently RadChart control doesn't support direct binding to Dictionary (and ObservableDictionary).
    In order to achieve a similar behavior you can bind the ItemsSource to a Collection (ObservableCollection) of your custom type, containing pair of "Keys" and "Values". 

    I hope that this approach is applicable for you.

    Regards,
    Vladislav
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top