Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 编译器错误MC3030:IEnumerable属性的所有者类必须实现IAddChild_.net_Wpf_Xaml_.net 4.0_Compiler Errors - Fatal编程技术网

.net 编译器错误MC3030:IEnumerable属性的所有者类必须实现IAddChild

.net 编译器错误MC3030:IEnumerable属性的所有者类必须实现IAddChild,.net,wpf,xaml,.net-4.0,compiler-errors,.net,Wpf,Xaml,.net 4.0,Compiler Errors,我正在尝试在.NET4.0客户端配置文件中构建一个自定义子类。我是这样开始的: public class MyPanel : Panel { public MyPanel() { } } 这可以很好地与XAML中的一些子控件集成(local是MyPanel所在命名空间的前缀): 到目前为止,很好,上面的XAML代码仍然可以编译 但是,我想在XAML中将一些元素添加到SomeList属性中,因此我写: <local:MyPanel> <local

我正在尝试在.NET4.0客户端配置文件中构建一个自定义子类。我是这样开始的:

public class MyPanel : Panel
{
    public MyPanel()
    {
    }
}
这可以很好地与XAML中的一些子控件集成(
local
MyPanel
所在命名空间的前缀):

到目前为止,很好,上面的XAML代码仍然可以编译

但是,我想在XAML中将一些元素添加到
SomeList
属性中,因此我写:

<local:MyPanel>
    <local:MyPanel.SomeList>
        <Button/>
    </local:MyPanel.SomeList>
    <Button/>
    <CheckBox/>
</local:MyPanel>
这应该行得通,但是不,没有编译时,我仍然收到相同的错误MC3030

我完全按照错误消息指示的那样做了,但错误并没有消失。我是否遗漏了编译器对我保密的任何其他修改?


报告似乎没有提到与这种情况有关的任何内容。此外,在谷歌上搜索连接到
IAddChild
WPF
的MC3030只会显示出与此相关的唯一结果。显然,错误MC3030是一个非常模糊的错误,到目前为止,很少有开发人员遇到过这个错误。

出现这个问题是因为该属性是作为泛型集合类型公开的。如果将属性类型从
IList
更改为
IList
,则错误应消失。如果属性表示最终将在设计器中具有某些可见效果的集合,则可能还需要考虑将设计器序列化可见性设置为内容。
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public IList SomeList
{
    get
    {
        return someList;
    }
}

对这并不理想,但我认为使用xaml中的泛型集合的唯一方法是创建自己的标记扩展(如中讨论的内容)。但是,由于属性由泛型集合支持,如果您尝试在其中放置错误的内容,则会出现异常。那么为什么它适用于内置类型,例如a的类型?我不确定您的意思。据我所知,XAML中使用的内置类型都不是泛型集合。他们总是很专业。您提到的属性是一个
ColumnDefinitionCollection
而不是一个
列表。
<local:MyPanel>
    <local:MyPanel.SomeList>
        <Button/>
    </local:MyPanel.SomeList>
    <Button/>
    <CheckBox/>
</local:MyPanel>
public class MyPanel : Panel, IAddChild
{
    public MyPanel()
    {
    }

    private readonly List<Button> someList = new List<Button>();

    public IList<Button> SomeList {
        get {
            return someList;
        }
    }

    public void AddChild(object value)
    {
        throw new NotImplementedException();
    }

    public void AddText(string text)
    {
        throw new NotImplementedException();
    }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public IList SomeList
{
    get
    {
        return someList;
    }
}