System.Stackoverflow异常发生在类中

时间:2014-04-29 14:05:04

标签: c# datagrid stack-overflow

我得到一个未处理的" System.StackOverflowException"以下Class中的错误。我将此Class类型的可观察集合绑定到Datagrid。请帮我查一下这段代码的错误。我遇到第一个属性Sno的错误,Get accessor本身。但是在实现INotifyPropertyChanged之前没有发生这种异常!

谢谢!

public class itemobject : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

   private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }


    public int Sno
    {
        get
        { return this.Sno; }

        set
        {
            if (value != this.Sno)
            {
                this.Sno = value;
                NotifyPropertyChanged();
            }
        }
    }
    public string name
    {
        get
        { return this.name; }

        set
        {
            if (value != this.name)
            {
                this.name = value;
                NotifyPropertyChanged();
            }
        }
    }
    public string unit
    {
        get
        { return this.unit; }
        set
        {
            if (value != this.unit)
            {
                this.unit = value;
                NotifyPropertyChanged();
            }
        }
    }

}

0 个答案:

没有答案