0

当我以这种方式设置构造函数时,为什么会出现编译错误:

  public class Castle
  {
        public Castle (bool mark, string description)
        {
            CastleMarked = mark;
            CastleDescription = description;
        }

        bool CastleMarked {get; set;}
        string CastleDescription {get; set;}
  }

然后以这种方式从其他地方初始化它:

Castle cas1 = new Castle(true,"Stone");
4

2 回答 2

2

可能是因为你还没有实现INotifyPropertyChanged接口。

这是什么:

CastleMarked  {get; set;}

财产类型在哪里?

编辑:

public之前添加class

编辑2:

你检查过还是只编辑你的问题;p?

因为这段代码工作正常:

namespace WpfApplication1
{
    public class Castle
    {
        public Castle(bool mark, string description)
        {
            CastleMarked = mark;
            CastleDescription = description;
        }

        bool CastleMarked { get; set; }
        string CastleDescription { get; set; }
    }

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Castle cas1 = new Castle(true, "Stone");
        }
    }
}
于 2013-06-24T19:56:28.680 回答
0

实现添加接口的方法。或者删除 Inotifypropertychanged。还修复属性,如private string property { get; set; }

于 2013-06-24T19:57:37.657 回答