我得到这个错误NullReferenceException was unhandled by user code
。错误发生在这一行
PropertyChanged(this, new PropertyChangedEventArgs("AboveAircraft"));
我试过if( this != null)
了,它仍然有错误。我该如何摆脱它?
代码如下所示:
public int AboveAircraft
{
get { return _above; }
set
{
if (SetProperty(ref _above, value, "AboveAircraft") && _updateModel)
{
if (Model.AltitudeBand == null)
{
Model.AltitudeBand = new AltitudeBand();
}
if (this != null && AboveAircraft != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("AboveAircraft"));
if (_above < _below)
{
BelowAircraft = _above;
}
}
Model.AltitudeBand .Above = new AltitudeBandLimit() { Unit = AltitudeUnit.Foot, Value = _above };
}
}
}