【问题标题】:How do you make a user control property of type collection<string> editable/setable in visual studio designer如何在 Visual Studio 设计器中使 collection<string> 类型的用户控件属性可编辑/可设置
【发布时间】:2009-10-07 05:03:32
【问题描述】:

我有一个自定义用户控件(在本例中为 web 控件),它具有 Collection 类型的属性

public class example : public System.Web.UI.UserControl
{
    public Collection<string> ThisIsTheCollection { get; set; }
}

当我将此控件添加到网络表单时,我希望能够在设计器中编辑此属性。它确实已经出现了,但我希望它在属性窗口中有一个 [...] 按钮,当您单击它时,它使您能够输入多个字符串。可能这也应该以某种方式反映在标记中。

谁能指出我正确的方向?

PS 该属性不必是 Collection 类型,如果其他一些通用集合类型更合适...

【问题讨论】:

    标签: c# .net asp.net visual-studio


    【解决方案1】:

    System.Windows.Forms.Design.StringCollectionEditor 是您正在寻找的。使用 Editor 属性将其分配给属性。

    [Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design",
    "System.Drawing.Design.UITypeEditor, System.Drawing")] 
    public Collection<string> ThisIsTheCollection { get; set; }
    

    【讨论】:

      【解决方案2】:

      从 UITypeEditor 派生一个新类并使用 Editor 属性应用于属性。

      【讨论】:

        猜你喜欢
        • 2011-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-03
        • 1970-01-01
        • 1970-01-01
        • 2016-03-08
        相关资源
        最近更新 更多