Events not triggered even though IsHitTestVisible is set to true

4 posts, 0 answers
  1. Terry
    Terry avatar
    19 posts
    Member since:
    Feb 2014

    Posted 02 Mar 2014 Link to this post

    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>
  2. Boris
    Admin
    Boris avatar
    276 posts

    Posted 04 Mar 2014 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Terry
    Terry avatar
    19 posts
    Member since:
    Feb 2014

    Posted 11 Mar 2014 in reply to Boris Link to this post

    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.






  5. Boris
    Admin
    Boris avatar
    276 posts

    Posted 14 Mar 2014 Link to this post

    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.

     
Back to Top