ChartItemClick

2 posts, 0 answers
  1. dennis
    dennis avatar
    39 posts
    Member since:
    Jun 2008

    Posted 20 Mar 2009 Link to this post

    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.
  2. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 23 Mar 2009 Link to this post

    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.
Back to Top