1

I'm trying to get vertical line annotations into my graph using MVVM. I have an AnnotationCollection on the ViewModel:

 public AnnotationCollection Lines
    {
        get
        {
            if (_lines == null)
            {
                _lines= new AnnotationCollection();
                foreach (var r in MyCollection)
                {
                    _lines.Add(
                        new VerticalLineAnnotation() {
                            X1 = r.Xvalue,
                            VerticalAlignment = VerticalAlignment.Stretch,
                            Y1 = 0,
                        }
                        );
                }
            }
            return _lines;
        }

Which I bind to in my view:

    <sci:SciChartSurface
                        ...
                        Annotations="{Binding Lines}"
                        ...

I know the binding is valid, because breakpoints hit in the getter (and it's not used anyplace else). I've examined the properties of the annotations, they seem to have a height, a width, a default Stroke and StrokeThickness. I've tried setting various additional properties manually. Yet whatever I do, the lines are never displayed on the graph. What am I doing wrong?

I've scoured the net for answers, but everything I've found so far seems to address older versions of SciChart API.

Shaggydog
  • 3,456
  • 7
  • 33
  • 50

1 Answers1

1

Solved: I'm using axes with AxisId defined in the view. I just needed to set the XAxisId and YAxisId for the annotations.

Shaggydog
  • 3,456
  • 7
  • 33
  • 50
  • Thanks for posting the solution! Also you might be interested SciChart WPF v5 will feature full MVVM support for annotations. Release is coming soon. – Dr. Andrew Burnett-Thompson Aug 07 '17 at 21:17
  • That's good to hear. I found it impossible to style my annotations in xaml (or at least I couldn't find a way). Will I be able to do this in the new version? – Shaggydog Aug 10 '17 at 14:08