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
- Chia Hsin Hu asked 5 years ago
- You must login to post comments
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
- Andrew Burnett-Thompson answered 5 years ago
-
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 login to post comments
Please login first to submit.