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

Events not triggered even though IsHitTestVisible is set to true

3 Answers 227 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 03 Mar 2014, 05:09 AM
Something is wrong with my event handling. Trying to throw a few events like KeyDown, SelectionChanged, and most importantly a notification that a Pan or Zoom has occurred via ChartPanAndZoomBehavior_Changed event handler.

Here is a XAML snippet, what is going on? Thanks in advance?

<telerik:RadCartesianChart Grid.Row="2" Name="chart2" Palette="Arctic" KeyDown="chart2_KeyDown" IsHitTestVisible="True" DragOver="chart2_DragOver"   >
            <telerik:RadCartesianChart.Behaviors>
                <telerik:ChartSelectionBehavior SelectionChanged="chart2_SelectionChanged">
                </telerik:ChartSelectionBehavior>
                
                <telerik:ChartTrackBallBehavior ShowTrackInfo="True" SnapMode="AllClosePoints" ShowIntersectionPoints="True">
                </telerik:ChartTrackBallBehavior>
                <telerik:ChartSelectionBehavior DataPointSelectionMode="Single" ></telerik:ChartSelectionBehavior>
                <telerik:ChartPanAndZoomBehavior  PanMode="Horizontal" ZoomMode="Horizontal" Changed="ChartPanAndZoomBehavior_Changed">
                </telerik:ChartPanAndZoomBehavior>
            </telerik:RadCartesianChart.Behaviors>

3 Answers, 1 is accepted

Sort by
0
Boris
Telerik team
answered on 04 Mar 2014, 10:08 AM
Hello Terry,

There are several changes you need to make to achieve the desired result:
  • You need to add an EventHadler for RadCartesianChart KeyDown event even if it has already been handled along its route. In code-behind call the attached method AddHandler(RoutedEvent, Delegate, Boolean) to add your handler. Specify the value of handledEventsToo as true like so :
  • public MainWindow()
            {
                InitializeComponent();
                this.AddHandler(RadCartesianChart.KeyDownEvent, new KeyEventHandler(chartView_KeyDown), true);
            }
     
    public void chartView_KeyDown(object sender, KeyEventArgs e)
            {
                ...
            }


  • The SelectionChanged event works fine.
  • In order to be notified that a Pan or Zoom has occurred you can use the ZoomChanged and PanOffsetChanged events of the RadCartesianChart.

Let us know if this helps.

Regards,
Boris Penev
Telerik
0
Terry
Top achievements
Rank 1
answered on 11 Mar 2014, 02:20 PM
Thanks Boris. I did not realize that I had to add certain handlers in the code behind as demonstrated in your post. Now that I have done that, my events seems to be working. A few additional comments however...

First, the ZoomChanged and PanOffsetChanged events behave more like a "Changing" event, rather than a "Changed" event. I want to fire the event when the user is finished zooming or panning, not while they are doing it. Is there a way to do that? Is there a way in those events to check if the user is still zooming and panning, maybe something like a state field. I didn't notice an easy way to make such a distinction. Perhaps I can combine it with a keydown/keyup event or something. Recommendations?
Second, when the event fires, what it gives me are X coordinates. However, the X-axis for me is a timeline with dates. Is there a way to translate the X-coordinate into my object space so I determine which daterange (or data points) are included within the X coordinates indicated by the events. 

Thanks.






0
Boris
Telerik team
answered on 14 Mar 2014, 01:50 PM
Hello Terry,

The PanOffsetChanged and ZoomChanged events are triggered when the PanOffset and Zoom properties are changed. There isn't any build-in logic to predict when the user has stropped zooming or panning. For example, if the user uses the mouse wheel to zoom there isn't any why to know if the user is going to keep zooming or whether he will decide to stop.

However, you can implement custom logic with a timer to detect when the PanOffsetChanged or ZoomChanged events were triggered. For example, you can check if either of those events were triggered in the last 1 second and if they haven't, then you may assume that the user has stopped zooming or panning. 

Regarding your last question, when a PanOffsetChanged event is triggered you receive the NewPanOffset and PreviousPanOffset values which are of type Point.They represent the offset of the newly visualized viewport of the RadChartView in pixels and not the X-axis elements. If you are using a DateTimeContinuousAxis as a horizontal axis you can check the ActualVisualRange property of the DateTimeContinuousAxis after zooming.

if (this.telerikChart != null)
            {
                var actualVisualRange = (this.telerikChart.HorizontalAxis as DateTimeContinuousAxis).ActualVisibleRange;
            }

On a side note we further investigated why the KeyDown event isn't triggered. As it turns out it is not because it is handled somewhere along the way but rather that the RadCartesianChart doesn't get focused. The given approach in my previous post is still valid. 

Please let us know if this helps.

Regards,
Boris Penev
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
ChartView
Asked by
Terry
Top achievements
Rank 1
Answers by
Boris
Telerik team
Terry
Top achievements
Rank 1
Share this question
or