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

Pie Chart: drill down behavior on selection via command

3 Answers 119 Views
Chart for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Matthew
Top achievements
Rank 1
Matthew asked on 11 Jun 2013, 03:33 PM
I've implemented a PieChart in a mvvm based Windows 8 store application. I found a thread that highlights how to use the SelectionChanged event of the behavior to perform drill down functionality. I was wondering if you have any example where commanding is used such that the viewmodel can handle processing the selection changed. Basically the challenge I see lies in passing the bound viewmodel item that is selected to the command. Any help would be greatly appreciated.

3 Answers, 1 is accepted

Sort by
0
Matthew
Top achievements
Rank 1
answered on 11 Jun 2013, 06:41 PM
I should probably provide a few more details...

I have created a behavior to handle the "SelectionChanged" event of "Telerik.UI.Xaml.Controls.Chart.ChartSelectionBehavior". This class follows suit with other behaviors that I have created to provide command functionality to controls. The problem I'm running into is actually a binding issue. How can I bind to the RelayCommand (implementing iCommand) of the view model. I'm using the below syntax. In the code sample below, both 'DivisionBreakdown' and 'BusinessUnitSelectedCommand' are properties of the view model.

<telerik:RadPieChart x:Name="divisionSpendingChart" Grid.Row="1" Grid.Column="1" Margin="8"  PaletteName="DefaultDark" EmptyContentTemplate="{StaticResource EmptyContentTemplate}" >
                        <telerik:PieSeries ItemsSource="{Binding DivisionBreakdown}" ShowLabels="True">
...
                        </telerik:PieSeries>
                        <telerik:RadPieChart.Behaviors>
                            <telerik:ChartSelectionBehavior DataPointSelectionMode="Single" common:TelerikPieChartSelectionChangedCommand.Command="{Binding BusinessUnitSelectedCommand}" />


The view model is the data context of the page the control resides in, and one of the properties of the view model is obviously bound to the ItemSource ofthe PieChart.

So my question is more along the line of how to get my binding expression setup such that the behavior I have created will work.
0
Accepted
Georgi
Telerik team
answered on 12 Jun 2013, 04:02 PM
Hello Mathew,

Thank you for contacting us and for your question.

There is a limitation in the current Windows Runtime state related to establishing valid bindings to custom objects that reside within a Collection property. There was a similar problem in the Silverlight framework and that problem was fixed with Silverlight v.4.0 and the DependencyObjectCollection<T> - used to delegate the proper data context (see the Remarks section).

So, at this point there is no way to implement the desired behavior using Bindings. The only possible way is to handle the SelectionChanged event in code behind and to manually raise a method on the ViewModel.

I hope this information is useful. Let me know if I can assist you in some other way.

Regards,
Georgi
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Matthew
Top achievements
Rank 1
answered on 12 Jun 2013, 04:06 PM
That is in fact the path I had reluctantly decided to to take. Thanks for looking into this and passing along the information!
Tags
Chart for XAML
Asked by
Matthew
Top achievements
Rank 1
Answers by
Matthew
Top achievements
Rank 1
Georgi
Telerik team
Share this question
or