0

私はそれをfigSpeed常にリフレしたいのですpSpeedが、メソッドでバインドすることにonChangeXなると、私は常にSystem.NullReferenceException

誰でも私を助けることができますか?参照が正しいようで、そうです。

PointsToPathConverterクラス:

[ValueConversion(typeof(List<Point>), typeof(Geometry))]
public class PointsToPathConverter : IValueConverter
{
    #region IValueConverter Members
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        List<Point> points = (List<Point>)value;

        if (points.Count > 0)
        {
            Point start = points[0];
            List<LineSegment> segments = new List<LineSegment>();

            for (int i = 1; i < points.Count; i++)
            {
                segments.Add(new LineSegment(points[i], true));
            }

            PathFigure figure = new PathFigure(start, segments, false); // true if closed
            PathGeometry geometry = new PathGeometry();
            geometry.Figures.Add(figure);
            return geometry;
        }
        else
        {
            return null;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotSupportedException();
    }
    #endregion
}

dataProjectorVMクラス:

public class dataProjectorVM : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public Path figSpeed;
    public List<Point> pSpeed;

    public dataProjectorVM()
    {
        pSpeed = new List<Point>();
        pSpeed.Add(new Point(0, 0));
        Binding bind;

        bind = new Binding("pSpeed")
        {
            Source = this,
            Mode = BindingMode.OneWay,
            Converter = new PointsToPathConverter(),
            UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
        };

        figSpeed = new Path()
        {
            Stroke = Brushes.Black,
            StrokeThickness = 1
        };

        figSpeed.SetBinding(Path.DataProperty, bind);
    }

    public void onChangeX()
    {
        pSpeed.Clear();
        double pm = -2;

        foreach (dataPacket dp in appMain.dataMgr.retrive.result)
        {
            double _pm = appMain.dataMgr.projector.getX(dp.pm);

            if (_pm > pm + 1)
            {
                pm = _pm;
                pSpeed.Add(new Point(pm, appMain.dataMgr.projector.getSpeedY(dp.speed)));
            }
        }

        this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("pSpeed"));
    }
}
4

1 に答える 1

0

PropertyChangedイベントにハンドラーがない場合、this.PropertyChangedはnullになります。

あなたはそれをチェックする必要があります。

于 2013-02-04T15:54:11.760 に答える