When designing controls, we often need to use our own defined classes as the control attributes,
However, unfortunately, IDE does not know the birth of a new category in advance. Therefore, we need
You can use TypeConverter to convert a custom object into a string and display it to the control.
In the property page of, put the character string in the property page (the color in aspx is also a string, such:
# Eef008) to a custom class.
The following two methods can be used to implement TypeConverter:
1. Apply the TypeConverter class defined by the system to convert custom attribute classes, such
ExpandableObjectConverter.
Ii. Apply your own TypeConverter class to convert custom attribute classes.
The first method is as follows: I have already provided an example in the previous article. We will focus on the second method. First, we will provide a suggestion.
Yes. If you want to use a custom TypeConverter class for conversion, it is best to inherit TypeConverter instead
This class inherits ExpandableObjectConverter and other classes inherited from TypeConverter.
Apply ExpandableObjectConverter to display attributes in a tree structure, and write TypeConverter
Yes, you can use the edit string to change the attribute settings. If you inherit
ExpandableObjectConverter, I found that sometimes when editing subattributes of class attributes, IDE sometimes does not
Update ParentProperty in time (Added policyparentproperty = true to the property of the custom class). Therefore,
It is best not to use the TypeConverter class written by yourself to inherit ExpandableObjectConverter.
You can modify the attributes of a Web control by modifying the sub-attributes of a class attribute or directly modifying the attributes of a string,
But sometimes there are some minor problems that make you feel uncomfortable.
Therefore, we recommend that you either apply ExpandableObjectConverter directly or inherit the property class written by yourself.
TypeConverter. do not inherit ExpandableObjectConverter.