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

TargetInvocationException occurred while binding to Dictionary

1 Answer 45 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Johannes
Top achievements
Rank 1
Johannes asked on 08 Nov 2013, 02:10 PM

Hi Telerik,

When I create a PieChart and set the Itemssource-Property to a Dictionary<string,decimal> a TargetInvocationException occurred.

My XAML:

<telerik:RadPieChart>
                        <telerik:RadPieChart.Series>
 
                            <telerik:PieSeries ShowLabels="True" ItemsSource="{Binding PieValues}"  >
                                <telerik:PieSeries.ValueBinding>
                                    <telerik:PropertyNameDataPointBinding PropertyName="Value" />
                                </telerik:PieSeries.ValueBinding>
                                <telerik:PieSeries.LabelDefinitions>
                                    <telerik:ChartSeriesLabelDefinition Margin="-10">
                                        <telerik:ChartSeriesLabelDefinition.Binding>
                                            <telerik:PropertyNameDataPointBinding PropertyName="Key" />
                                        </telerik:ChartSeriesLabelDefinition.Binding>
                                    </telerik:ChartSeriesLabelDefinition>
                                </telerik:PieSeries.LabelDefinitions>
                            
                            <telerik:PieSeries.AngleRange>
                                <telerik:AngleRange StartAngle="270" SweepAngle="360" />
                            </telerik:PieSeries.AngleRange>
                        </telerik:PieSeries>
                        </telerik:RadPieChart.Series>
                    </telerik:RadPieChart>

The PieValue ist a

Dictionary<string, decimal>


The Error Occurred on "OnPropertyChanged(() => PieValues);"


Dear Johannes

1 Answer, 1 is accepted

Sort by
0
Peshito
Telerik team
answered on 13 Nov 2013, 01:05 PM
Hello,

Thank you for the attached code snippets, I was able to create a new project and reproduce the issue at hand.

You are using a Dictionary as ItemsSource. However, the Dictionary is IEnumerable<KeyValuePair>. The KeyValuePair is not a class, but a struct, and it is a limitation of the chart that properties of struct objects cannot be evaluated. What you can do, is using another collection type instead.

Regards,
Peshito
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
ChartView
Asked by
Johannes
Top achievements
Rank 1
Answers by
Peshito
Telerik team
Share this question
or