用户/Web 控件设计时支持 C# 枚举列表/集合吗?

发布于 2024-08-26 06:14:33 字数 1102 浏览 5 评论 0原文

自周四以来,我一直在为这个小问题而头撞砖墙,但我仍然没有比当时更接近答案。

我有一个用户控件,它具有这样的属性:

/// <summary>
/// Gets or sets the media types.
/// </summary>
/// <value>The media types.</value>
public List<MediaType> MediaTypesFilter { get; set; }

MediaType 是一个枚举,包含 None、PDF、Image 等。

我希望能够在设计时设置用户控件的媒体类型(使用智能感知),例如:

<CMS:MediaPicker ID="MediaPicker runat="server" MediaTypesFilter="PDF, Image">

或者也许更有可能导致这样的结果:

<CMS:MediaPicker ID="MediaPicker" runat="server">
    <MediaTypesFilter>
        <MediaType>PDF</MediaType>
        <MediaType>Image</MediaType>
    </MediaTypesFilter>
</CMS:MediaPicker>

我认为我需要在属性上使用属性,例如 DesignerSerializationVisbility 等,但我无法弄清楚。我读过有关 CollectionEditors 的内容,我读到的内容表明默认的 CollectionEditor 应该能够处理这个问题,所以我认为我不需要创建一个自定义的 CollectionEditor。到目前为止,我得到的最接近的是一个内部属性,无法设置媒体类型。我似乎找不到任何在设计时使用枚举列表作为属性的示例。有人可以为我指明正确的方向,或者向我展示一些示例代码来完成我想要做的事情吗?

现在,我最终得到了一个逗号分隔的字符串,并且在需要时以编程方式将其拆分为一个列表,但这意味着在设计时没有智能感知,这很糟糕。

I've been banging my head against a brick wall over this little problem since thursday and I'm still no nearer to an answer than I was back then.

I have a user control which has a property like this:

/// <summary>
/// Gets or sets the media types.
/// </summary>
/// <value>The media types.</value>
public List<MediaType> MediaTypesFilter { get; set; }

MediaType is an enum, containing None, PDF, Image, etc.

What I would like is to be able to set the user control's mediatypes in the design time (with intellisense), e.g:

<CMS:MediaPicker ID="MediaPicker runat="server" MediaTypesFilter="PDF, Image">

or perhaps it's more likely to result in something like this:

<CMS:MediaPicker ID="MediaPicker" runat="server">
    <MediaTypesFilter>
        <MediaType>PDF</MediaType>
        <MediaType>Image</MediaType>
    </MediaTypesFilter>
</CMS:MediaPicker>

I think I need to use attributes on the property, such as DesignerSerializationVisbility, etc, but I can't figure it out. I've read about CollectionEditors, and what I've read suggests that the default CollectionEditor SHOULD be able to handle this, so I don't think I need to create a custom CollectionEditor. The closest I've got so far was an inner property with no ability to set which media types. I can't seem to find any examples of Enum lists as properties being used at the design time. Can someone point me in the right direction or show me some sample code doing what I'm attempting to do?

For now, I've ended up with a comma separated string, and will just split it out into a list programmatically when I need it, but this means no intellisense at design time, which sucks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初熏 2024-09-02 06:14:33

尝试添加 可浏览 属性。请参阅示例

[Browseable(true)]

不要忘记添加 using System.ComponentModel;

另外,请参阅扩展具有自定义 HTML 属性的 ASP.NET Web 控件

Try adding Browseable attribute. See example.

[Browseable(true)]

Dont forget to add using System.ComponentModel;

Also, see Extending ASP.NET Web Controls With Custom HTML Attributes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文