Pre loader

CustomAnnotation X1, Y1 and X2, Y2 is null when creating

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

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

  • John-Anders Persson
    How do you set X1,X2 and Y1,Y2 in xaml ? I also get null values here when using Comp[osite Annotations example. the suggestion to set the value DependencyProperty.SetCurrentValue(X1Property, 0.0); does not work since DependencyProperty does not expose a SetCurrentValue methid (?)
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies