向 SciChart BoxAnnotation 添加更多手柄

Add more grip handles to a SciChart BoxAnnotation

我正在寻找一种方法来将手柄添加到框注释的左中心和右中心(位置如下所示,带有红色圆圈)。默认情况下,仅在 BoxAnnotation 的四个角上创建手柄。

目前,我正在代码隐藏和视图模型中创建注释,而不是 XAML。

我尝试通过组合 LineAnnotation 和 BoxAnnotation 创建自定义 composite annotation。但是,LineAnnotation 夹点手柄仅影响线而不影响整个复合注释。

    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
            });
        }
     }

更新: 回应 答案。将代码从构造函数移至 OnLoaded 方法并不能解决问题。唯一显示的手柄位于左上角、右上角、左下角和右下角。

我认为你不应该在 ctor 中添加。尝试添加加载功能。

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;
    }
}