Annotation features

4 posts, 0 answers
  1. Carlo
    Carlo avatar
    5 posts
    Member since:
    Aug 2013

    Posted 10 Sep 2013 Link to this post

    Hello, a few questions about this feature:

    1) Is it possible to show a tooltip on annotations?
    2) Is it possible to have a click event (mousedown / mouseup should be fine too) on annotations to do something in response of a click?
    3) Is it possible to update the way an annotation looks based on the mouse being over the annotation? I tried with style triggers but it didn't work.

    Thanks!
  2. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 13 Sep 2013 Link to this post

    Hi Carlo,

    Thanks for contacting us.

    1, 2, 3 - Yes, you just need to set the IsHitTestVisible property to true (all WPF mouse events are supported). 

     Here's an example:
    <telerik:CartesianGridLineAnnotation Axis="{Binding ElementName=vAxis}" Value="30"
            StrokeThickness="4"
            ToolTip="This is a tooltip"
            IsHitTestVisible="True"
            MouseEnter="CartesianGridLineAnnotation_MouseEnter"
            MouseLeave="CartesianGridLineAnnotation_MouseLeave"
            MouseLeftButtonUp="CartesianGridLineAnnotation_MouseLeftButtonUp"/>
    private void CartesianGridLineAnnotation_MouseEnter(object sender,
                                          MouseEventArgs e)
    {
        var annotation = sender as CartesianGridLineAnnotation;
        annotation.StrokeThickness += 2;
     
    }
     
    private void CartesianGridLineAnnotation_MouseLeave(object sender,
                                          MouseEventArgs e)
    {
        var annotation = sender as CartesianGridLineAnnotation;
        annotation.StrokeThickness -= 2;
    }
     
    private void CartesianGridLineAnnotation_MouseLeftButtonUp(object sender,
                                                 MouseButtonEventArgs e)
    {
        var annotation = sender as CartesianGridLineAnnotation;
        annotation.Effect = annotation.Effect == null ? new BlurEffect() : null;
    }

    I hope this helps.
     
    Regards,
    Petar Kirov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Carlo
    Carlo avatar
    5 posts
    Member since:
    Aug 2013

    Posted 24 Sep 2013 Link to this post

    Hello Petar, thanks for your reply.

    They all worked except MouseLeftButtonUp, I tried both the tunnel (Preview) and bubbling strategies, but they did not do the trick. Also, I'm trying it in a CartesianCustomAnnotation and I'm creating them through code, I wonder if that makes a difference:

    foreach (MyItem item in items)
                {
                    CartesianCustomAnnotation customAnnotation = new CartesianCustomAnnotation
                    {
                        HorizontalAxis = MyChartHorizontalAxis,
                        VerticalAxis = MyChartVerticalAxis,
                        HorizontalValue = item.StateChangedTime,
                        IsHitTestVisible = true,
                        Content = new Border()
                        {
                            Background = new SolidColorBrush(Colors.Red),
                            Child = new TextBlock
                            {
                                Text = "Completed Item"
                            }
                        },
                        Style = (Style)FindResource("CompletedWorkOrderAnnotationStyle")
                    };
     
                    MyChartControl.Annotations.Add(customAnnotation);
     
                    customAnnotation.MouseLeftButtonUp += customAnnotation_MouseLeftButtonUp; // Doesn't work
                    customAnnotation.MouseEnter += customAnnotation_MouseEnter;
                    customAnnotation.MouseLeave += customAnnotation_MouseLeave;
                }
  5. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 27 Sep 2013 Link to this post

    Hi Carlo,

    I believe that you have added a ChartPanAndZoomBehavior to the RadCartesianChart.Behaviors collection with its DragMode set to Pan or Zoom (default is Zoom). If that is so, the chart will capture some mouse events (used for panning or zooming) and as a consequence annotations will not receive them. 
    To workaround this, you can use a combination of RadCartesianChart.MouseLeftButtonUp and the annotation.MouseLeftButtonDown (or only button down, if this is enough for you):
    Point lastMouseLeftButtonDownPosition = new Point(-1, -1);
     
    void customAnnotation_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        this.lastMouseLeftButtonDownPosition = e.GetPosition(this.chart);
    }
     
    void chart_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        var pos = e.GetPosition(this.chart);
        var cp = this.customAnnotation.FindChildByType<ContentPresenter>();
        double left = Canvas.GetLeft(cp);
        double top = Canvas.GetTop(cp);
        double width = cp.ActualWidth;
        double height = cp.ActualHeight;
     
        //Ensure that lastMouseLeftButtonDownPosition is within the annotation rectangle
    }

     

    Regards,
    Petar Kirov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top