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

ChartItemClick

1 Answer 36 Views
Chart
This is a migrated thread and some comments may be shown as answers.
dennis
Top achievements
Rank 1
dennis asked on 20 Mar 2009, 02:24 PM
is there any way to access the radchart who invoked the method???
i only can access to the bar. whne i debug i can see that the bar has a private variable "parent" that references to the RadChart.
but the public property "Parent" is null.

1 Answer, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 23 Mar 2009, 10:51 AM
Hello dennis,

You can get access to the chart parent by walking the visual tree of the control like this:

using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Media; 
using Telerik.Windows.Controls; 
using Telerik.Windows.Controls.Charting; 
 
namespace SilverlightApplication2 
    public partial class Page : UserControl 
    { 
        public Page() 
        { 
            InitializeComponent(); 
 
            DataSeries series = new DataSeries() { new DataPoint(1,10), new DataPoint(2,20), new DataPoint(3, 30) }; 
            RadChart1.DefaultView.ChartArea.DataSeries.Add(series); 
 
            RadChart1.DefaultView.ChartArea.ChartItemClick += ChartArea_ChartItemClick; 
        } 
 
        private void ChartArea_ChartItemClick(object sender, ChartItemClickEventArgs e) 
        { 
            RadChart chart = GetVisualParent<RadChart>(e.OriginalSource as DependencyObject); 
        } 
 
        private static TParent GetVisualParent<TParent>(DependencyObject dependencyObject) where TParent : DependencyObject 
        { 
            DependencyObject parent = null
 
            if (dependencyObject != null
                parent = VisualTreeHelper.GetParent(dependencyObject); 
 
            while ((parent != null) && !(parent is TParent)) 
            { 
                parent = VisualTreeHelper.GetParent(parent); 
            } 
 
            return (TParent)parent; 
        } 
    } 


We will also consider exposing the chart parent in a more straightforward manner for the future releases of the control.


Regards,
Manuel
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Chart
Asked by
dennis
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Share this question
or