0

Im trying to edit some data within a class which is linked to with databinding. Here is my class:

public class Line
{
    public string Equation { get; set; }
    public int PreviousLine { get; set; }
    public int LineNumber { get; private set; }

    public Line()
    {
        this.LineNumber = (this.PreviousLine + 5);
    }
}

however the line number always returns 5, even if previous line is set to 6...

here is how I link to it within my viewmodel:

this.Lines.Add(new Line { Equation = "5*2", PreviousLine = 6 });

thanks

4

2 回答 2

0

try declaring it as static.

public static int PreviousLine { get; set; }
于 2013-03-01T05:52:35.917 回答
0
 private int _previousLine;
    public int PreviousLine
    {
        get { return _previousLine; }
        set { _previousLine = value;
            Line = _previousLine + 5;
        }
    }
    public int Line { get; private set; }
于 2013-03-01T05:55:11.173 回答