WPF OnNotifyPropertyChange实例化对象时引发null异常

时间:2017-09-12 15:53:55

标签: c# wpf

我刚刚在数据库中添加了一个字段,并且必须使用EF从数据库更新模型。但是,该模型显示所有正确的字段及其类型。 Estimate类也会实现INotifyPropertyChanged。这在更新数据库之前有效,但不确定南方是什么

从调试器中旅行时:

CurrentEstimate = new Estimate();

To(因为此属性正在改变):

private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

我得到一个空引用异常。

propertyName是“CurrentEstimate”,CurrentEstimate一旦到达null函数就不是NotifyPropertyChanged

CurrentEstimate的实施:

    private Estimate _estimate;
    public Estimate CurrentEstimate
    {
        get { return _estimate; }
        set { _estimate = value; NotifyPropertyChanged(); }
    }

1 个答案:

答案 0 :(得分:0)

虽然异常被抛出:

PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

自定义转换器是罪魁祸首。

相关问题