C# Enum List/Collection on User/Web Control design time support?
I've been banging my head against a brick wall over this little problem since thursday and I'm still no neare开发者_C百科r 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.
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.
精彩评论