当我以这种方式设置构造函数时,为什么会出现编译错误:
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");
答案 0 :(得分:2)
可能是因为您尚未实施INotifyPropertyChanged
界面。
这是什么:
CastleMarked {get; set;}
哪里是财产类型?
修改强>
在public
class
<强> EDIT2:强>
你有没有检查过,或者你只是在编辑你的问题; 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");
}
}
}
答案 1 :(得分:0)
实现添加接口的方法。或者删除Inotifypropertychanged。同时修复private string property { get; set; }