用户/Web 控件设计时支持 C# 枚举列表/集合吗?
自周四以来,我一直在为这个小问题而头撞砖墙,但我仍然没有比当时更接近答案。
我有一个用户控件,它具有这样的属性:
/// <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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加 可浏览 属性。请参阅示例。
不要忘记添加
using System.ComponentModel;
另外,请参阅扩展具有自定义 HTML 属性的 ASP.NET Web 控件。
Try adding Browseable attribute. See example.
Dont forget to add
using System.ComponentModel;
Also, see Extending ASP.NET Web Controls With Custom HTML Attributes.