SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components

Answered
0
0

hello, i have a problem, my TestAnnotation class X Y is null when creating.

code:

public class TestAnnotationViewModel : CompositeAnnotationViewModel
{
    public override Type ViewType
    {
        get { return typeof(TestAnnotation); }
    }
}

public class TestAnnotation : CompositeAnnotation
{
    public TestAnnotation() : base()
    {
        DefaultStyleKey = typeof(CompositeAnnotation);
    }

    public override void Update(ICoordinateCalculator<double> xCoordCalc, ICoordinateCalculator<double> yCoordCalc)
    {
        base.Update(xCoordCalc, yCoordCalc);

        //i want to do some thing, but X1 Y1 X2 Y2 is null, and i get exception.
        //this code from Composite Annotations Examples
        if (Y1.CompareTo(Y2) > 0) // <===exception
        {
            MeasureText.VerticalAnchorPoint = VerticalAnchorPoint.Top;
            MeasureText.Margin = new Thickness(0, 5, 0, 0);
        }
        else
        {
            MeasureText.VerticalAnchorPoint = VerticalAnchorPoint.Bottom;
            MeasureText.Margin = new Thickness(0, -5, 0, 0);
        }
    }
}

version v5.3.0.11954

Version
5.3.0.11954
  • You must to post comments
Great Answer
0
0

Yes, you need to set X1,X2,Y1,Y2, or test for null if you override the Update() method.

This is because X1,X2,Y1,Y2 are dependency properties. Not setting them gives a value of DependencyProperty.UnsetValue. When cast to IComparable, this is null.

Set a default value, either in XAML, in a style, or by using DependencyProperty.SetCurrentValue(X1Property, 0.0); in the constructor of the custom annotation

Best regards
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

SciChart WPF v6 BETA released! Note pricing/licensing changes are coming. Contact us to beat the rise!Read more
+