wpf 该类型不包含任何可访问的构造函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17283953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:04:02  来源:igfitidea点击:

The type does not include any accessible constructors

c#wpfconstructor

提问by Sturm

Why do I get that compile error when I set the constructor this way:

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

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

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

And then initialize it from other place this way:

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

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

回答by Wojciech Kulik

Probably because you haven't implemented INotifyPropertyChangedinterface.

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

And what is this:

这是什么:

CastleMarked  {get; set;}

where is type of property?

财产类型在哪里?

EDIT:

编辑:

add publicbefore class

添加public之前class

EDIT2:

编辑2:

Have you checked that or are you only editing your question ;p?

你有没有检查过,或者你只是在编辑你的问题;p?

Because this code works fine:

因为这段代码工作正常:

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");
        }
    }
}

回答by iefpw

Implement add the methods of the interface. Or remove the Inotifypropertychanged. Also fix the properties like private string property { get; set; }

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