I’ve been beating my head over this for a while and I’m wondering if there’s something wrong with my implementation or whether there’s a bug in the annotationlabel.
I am running into a nullreferenceexception when I begin drag on an Axis AnnotationLabel attached to a VerticalLineAnnotation. An example code is below. This doesn’t seem to be an issue for non-axis labels.
I am able to drag once. When I begin my second drag on the label the crash occurs. This crash does not occur when the annotation line itself is dragged. The crash occurs when you click on the annotation label (at the axis) and drag it twice in succession.
Note — this issue doesn’t crop up when the annotation and label are declared in xaml. For my purposes however, I have been trying to create them programmatically. My actual code is a bit different, I add the label in the codebehind as opposed to the viewmodel, but this below gives the same outcome.
Edit: on further investigation, this seems to occur with annotationviewmodels specifically. Creating the annotation through the codebehind works fine. But creating it via an AnnotationsBinding and annotationviewmodel does not. I found the issue occurs when I set “ShowLabel” on the annotationviewmodel as well as when I add to the label collection.
var a = new VerticalLineAnnotationViewModel()
{
X1 = someInitialVal,
XAxisId = "DateTimeXAxis",
YAxisId = "PressureYAxis",
DragDirections = SciChart.Charting.XyDirection.XDirection,
IsEditable = true,
};
a.AnnotationLabels.Add( new SciChart.Charting.Visuals.Annotations.AnnotationLabel() );
Annotations.Add( a);
RaisePropertyChanged( nameof( Annotations ) );
- John Chow asked 3 years ago
- last edited 3 years ago
- You must login to post comments
If anyone else is running into the same issue, the workaround I found is overriding OnAnnotationMouseMove in the Annotation and returning without calling base if the sender is not the annotation (i.e. is the label or one of the elements in the label).
- John Chow answered 3 years ago
- You must login to post comments
It just happened in our application earlier today:
> EXCEPTION OCCURRED:System.NullReferenceException: Object reference not
> set to an instance of an object. at
> SciChart.Charting.Visuals.Annotations.VerticalLineAnnotation.MoveAnnotationTo(AnnotationCoordinates
> coordinates, Double horizOffset, Double vertOffset) at
> SciChart.Charting.Visuals.Annotations.AnnotationBase.OnAnnotationPointerMoved(ModifierMouseArgs
> e) at
> SciChart.Charting.Visuals.Annotations.AnnotationBase.OnAnnotationMouseMove(Object
> sender, MouseEventArgs e)
We have had similar issues with NRE in ToCoordinates()
method. We had to create a child class of VerticalLineAnnotationForMvvm
and override ToCoordinates()
. Since all arguments to MoveAnnotation
are value objects the only possibility is that canvas
is null for some reason.
- Alexander Gdalevich answered 4 months ago
- last edited 4 months ago
- You must login to post comments
Please login first to submit.