Search code examples
c#scichart

Add more grip handles to a SciChart BoxAnnotation


I'm looking for a way to add grip handles to the left-center and right-center of a box annotation (locations shown below with red circles). By default, grip handles are only created on the four corners of the BoxAnnotation.

GripHandleLocations

Currently, I am creating my annotations in the code behind and view models, not XAML.

I've tried creating a custom composite annotation by combing a LineAnnotation and BoxAnnotation. However, the LineAnnotation grip handles only effect the line and not the composite annotation as a whole.

    class MyCompositeAnnotation : CompositeAnnotation
    {
        public MyCompositeAnnotation()
        {
            //BoxAnnotation
            Annotations.Add(new BoxAnnotation
            {
                CoordinateMode = AnnotationCoordinateMode.Relative,
                IsEditable = false,
                ResizeDirections = SciChart.Charting.XyDirection.XDirection,
                Background = grayBrushLight,
                BorderBrush = grayBrushRegular,
                X1 = 0,
                X2 = 1,
                Y1 = 0,
                Y2 = 1
            });

            //Center dashed line
            Annotations.Add(new LineAnnotation
            {
                CoordinateMode = AnnotationCoordinateMode.Relative,
                Stroke = grayBrushRegular,
                StrokeThickness = 1,
                IsEditable = true,
                ResizeDirections = SciChart.Charting.XyDirection.XDirection,
                StrokeDashArray = new DoubleCollection(new double[] { 2, 4 }),
                X1 = 0,
                X2 = 1,
                Y1 = 0.5,
                Y2 = 0.5
            });
        }
     }

UPDATE: In response to the Seçkin Durgay's answer. Moving the code from the constructor to the OnLoaded method does not fix the issue. The only grip handles shown are on the top-left, top-right, bottom-left, and bottom-right corners.

CompositeAnnotation


Solution

  • I think you shouldn't add in ctor. Try to add loaded function.

    class MyCompositeAnnotation : CompositeAnnotation
    {
    
        public MyCompositeAnnotation()
        {
            Loaded+=OnLoaded;
    
        }
    
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            //BoxAnnotation
            Annotations.Add(new BoxAnnotation
            {
                CoordinateMode = AnnotationCoordinateMode.Relative,
                IsEditable = false,
                ResizeDirections = SciChart.Charting.XyDirection.XDirection,
                Background = grayBrushLight,
                BorderBrush = grayBrushRegular,
                X1 = 0,
                X2 = 1,
                Y1 = 0,
                Y2 = 1
            });
    
            //Center dashed line
            Annotations.Add(new LineAnnotation
            {
                CoordinateMode = AnnotationCoordinateMode.Relative,
                Stroke = grayBrushRegular,
                StrokeThickness = 1,
                IsEditable = true,
                ResizeDirections = SciChart.Charting.XyDirection.XDirection,
                StrokeDashArray = new DoubleCollection(new double[] { 2, 4 }),
                X1 = 0,
                X2 = 1,
                Y1 = 0.5,
                Y2 = 0.5
            });
            Loaded -= OnLoaded;
        }
    }