服务器控件集合属性无法在设计器中添加

时间:2014-02-14 09:36:51

标签: c# asp.net designer custom-server-controls

我有一个具有集合属性的自定义服务器控件。我希望能够从设计器中添加集合属性中的项目,并在标记中查看结果。 到目前为止,我能够在设计器中看到集合属性,并添加了一个项目。但是,它不会为新项目生成标记。 以下是我的代码的一部分:

[ParseChildren(true),
DefaultProperty("CompatibleBrowsers"),
Designer(typeof(BrowserCompatibilityControlDesigner)),
ToolboxData("<{0}:BrowserCompatibilityControl runat=server></{0}:BrowserCompatibilityControl>")]
public class BrowserCompatibilityControl : WebControl
{
    private List<CompatibleBrowser> _CompatibleBrowsers = new List<CompatibleBrowser>();

    public BrowserCompatibilityControl() : base() { }

    [Bindable(true)]
    [Category("Behavior")]
    [DefaultValue("")]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
    Editor(typeof(BrowserCollectionEditor), typeof(UITypeEditor)),
    NotifyParentProperty(true),
    PersistenceMode(PersistenceMode.InnerProperty)]
    public List<CompatibleBrowser> CompatibleBrowsers { get { return _CompatibleBrowsers; } }

    ...
}

收集项目的类型为CompatibleBrowser

[TypeConverter(typeof(ExpandableObjectConverter))]
public class CompatibleBrowser
{
    BrowserName _Name;
    int _MinVersion, _MaxVersion;

    public CompatibleBrowser() : this(BrowserName.Default, 0, 0) { }

    public CompatibleBrowser(BrowserName name, int minVersion, int maxVersion)
    {
        Name = name;
        MinVersion = minVersion;
        MaxVersion = maxVersion;
    }

    [
    Category("Behavior"),
    DefaultValue(""),
    Description("Name of browser"),
    NotifyParentProperty(true),
    ]
    public BrowserName Name { get { return _Name; } set { _Name = value; } }
    [
    Category("Behavior"),
    DefaultValue(""),
    Description("MinVersion"),
    NotifyParentProperty(true),
    ]
    public int MinVersion { get { return _MinVersion; } set { _MinVersion = value; } }
    [
    Category("Behavior"),
    DefaultValue(""),
    Description("MaxVersion"),
    NotifyParentProperty(true),
    ]
    public int MaxVersion { get { return _MaxVersion; } set { _MaxVersion = value; } }
}

标记看起来像这样:

<test:BrowserCompatibilityControl runat="server">
    <CompatibleBrowsers>
        <test:CompatibleBrowser Name="IE" MinVersion="9" />
        <test:CompatibleBrowser Name="Chrome" MinVersion="27" />
        <test:CompatibleBrowser Name="Mozilla" MinVersion="21" />
        <test:CompatibleBrowser Name="Opera" MinVersion="9" />
    </CompatibleBrowsers>
    ...
</test:BrowserCompatibilityControl>

0 个答案:

没有答案