views:

20

answers:

1

I am building a usercontrol which can display data with many flags. I would like to be able to able to declare it this way, or something similar to that from the asp.net page

<ctl:DisplayItem runat="server" id="ctlTest">
  <flags>
    <flagIsAvailable />
    <flagIsInError />
  </flags>
</ctl:DisplayItem>

In my control, the flags would be a List(of PossibleFlags)

Public Enum PossibleFlags
  IsInError
  IsAvailable
End Enum

Public Property Flags as List(Of PossibleFlags)

Note: If possible, I would also like to know how to do it for properties that are of a custom type (not just lists or generics)

A: 

Add something like this to you control. (i took it from one of my server controls so might need some refactoring to suit your need, but you'll get the idea)

Property:

        List<MyFlag> _flags = null;            

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [NotifyParentProperty(true)]
        public List<MyFlag> Flags
        {
            get
            {                    
                if (_flags == null)
                {
                    _flags = new List<MyFlag>();                        
                }

                return _flags;
            }
        }

The class:

        public class MyFlag
        {                       
            public bool FlagIsAvailable { get; set;}
            public bool FlagIsInError { get; set;}                      
        }
Jeroen