Properties and properties pane
In the previous article, I discussed the relationship between attributes and the HTML style label and text in the aspx file. I missed two points:
1. The difference between encodedinnerdefaultproperty and innerdefaproperty property may be unclear to some friends,
The encodedinnerdefaultproperty attribute cannot contain control objects. For example, the text attribute of datalist that declares encodedinnerdefaultproperty is
You cannot set it to <Table...> ..... </table>. And declared
You can write content like <asp: datalist value = "1"> 1 </ASP: datalist> to the items attribute of dropdownlist of innerdefaproperty property.
2. What if an attribute cannot be controlled in the aspx file?
We can use this attribute:
Designerserilizationvisibility (designerserializationvisibility. Hidden)
OK. Now let's go to the topic: PROPERTIES AND PROPERTIES pane.
I believe that most programmers use the attribute pane to set the properties of the control object in most cases. Therefore, the attribute pane is also crucial in the control design.
When talking about the attribute pane, let's first take a look at propertygrid. propertygrid is a control located in system. Windows. Forms. dll, and IDE such as vs.net.
A tool is used to provide attribute display and operation functions. You may not have the concept of this control at ordinary times, although you may be using its functions every day.
If you want to learn more about it, you can create a winform project, add the control to the vs.net toolbox, and then pull it to the form to learn about it, this tool is usually not used for programming, but it is good to use it when you want to provide a custom designer (such as the DataGrid Attribute Editor) for the control.
Idea (for more things about various design tools and propertygrid, I will talk about the functions in future control design ).
Propertygrid can display the properties of a control in multiple forms,
For example, for the font attribute of a button, properygrid shows it as an expandable and collapsed attribute group. First, the font attribute type is a complex class.
(Fontinfo), which has many sub-attributes. Then, you need to apply the attribute we mentioned above:
Designerserializationvisibility (designerserializationvisibility. Content)
It indicates that the code generator will serialize the sub-attribute of the attribute rather than itself. How can this problem be solved? That is to say, the bold and underline sub-attributes in the font attribute of the button control
Serialize to (font-underline = "true" font-bold = "true") instead of serialized to (style = "Z-INDEX: 101;
Left: 224px; position: absolute; top: 240px "), and in general, we will set another attribute and its value for this attribute:
[Policyparentproperty (true)] (system. componentmodel. policyparentpropertyattribute, default value: false)
Propertygrid notifies the parent of a change from the sub-attribute.
The default value of designerserializationvisibility is designerserializationvisibility. Visible. the previously mentioned hidden value will make the corresponding attribute not sequential
For example, if you create a sqlserverconnection control, you do not want to provide the user with the serialization of the connectpassword attribute and write it in the. aspx file.
Yes. At the same time, the property set to hidden will not appear in propertygrid.
If I want to serialize and set the attribute value in the. aspx file instead of displaying it in propertygrid
[Browsable (false)] is used. The default value of this attribute is true. The full name is system. componentmodel. browsableattribute.
Next, programmers generally do things in a more organized way, just like me :), so we will want to place various properties of controls in propertygrid.
To do this, you only need to add the following attribute above the attribute declaration:
[Category ("behavior")] (system. componentmodel. categoryattivity, its default value is "default ").
Note that you do not need to write [category ("behavior")] for categories such as data, appearance, behavior, and miscellaneous (default). written as [category ("behavior")],
Vs.net will automatically perform localization.
Next, you may want to write a few comments for the attribute. You can use this attribute:
[Description ("have you written the control today")] (system. componentmodel. descriptionattribute, you may want to localize this attribute so that you can see the annotations.
This is also acceptable when people talk about things, but it is not as automatic as category. There are many things to be done. We will discuss the control localization later)
Now, let's take a look at propertygrid's support for several different styles for editing properties:
Text Box, drop-down, and pop-up window.
The text box is default, such as the text of the button;
Drop-down validation type, such as the rocktocontrol attribute of the rockucontrol Control I wrote and the property of the validation object selected for the validator control series;
A window is displayed, such as the color attribute. A form is provided for us to select.
The first one is the default one. We don't need to worry about it. Let's look at the drop-down menu. To achieve this effect, we need to use an attribute that is different from the other:
[Typeconverter (typeof (yourcustomconverter)]
For example, the rocktocontrol attribute of my rockucontrol Control
[Bindable (false)]
[Category ("behavior")]
[Defaultvalue ("")]
[Typeconverter (typeof (thincontrols. webcontrols. Designer. formcontrolsconverter)]
[Description ("the object to be rolled. ")]
Public String rocktocontrol
{
Get
{
Object o = viewstate ["rocktocontrol"];
Return (O = NULL )? "": O. tostring ();
}
Set
{
Viewstate ["rocktocontrol"] = value;
}
}
Let's look at the formcontrolsconverter class again (Please carefully check the comments I added)
Public class formcontrolsconverter: stringconverter
{
Public formcontrolsconverter ()
{
}
// This override description must be used to edit attributes in the drop-down list.
Public override bool getstandardvaluessupported (itypedescriptorcontext context)
{
Return true;
}
// This override returns the drop-down list item. A friend once asked how to implement the control of the current page. below is the code I found out.
Public override system. componentmodel. typeconverter. standardvaluescollection getstandardvalues (itypedescriptorcontext context)
{
Controlcollection controls = (PAGE) context. Container. components [0]). controls;
Arraylist controlsarray = new arraylist ();
For (INT I = 0; I <controls. Count; I ++)
{
If (controls [I] Is htmltable
| Controls [I] Is htmlform
| Controls [I] Is htmlgenericcontrol
| Controls [I] Is htmlimage
| Controls [I] Is label
| Controls [I] Is DataGrid
| Controls [I] Is datalist
| Controls [I] is table
| Controls [I] Is Repeater
| Controls [I] is image
| Controls [I] is panel
| Controls [I] Is placeholder
| Controls [I] is Calendar
| Controls [I] Is adrotator
| Controls [I] is XML
))
{
Controlsarray. Add (controls [I]. clientid );
}
}
Return new standardvaluescollection (controlsarray );
}
// Return true can only be selected. Return flase is optional.
Public override bool getstandardvaluesexclusive (itypedescriptorcontext context)
{
Return false;
}
}
It is difficult to pop up the form (uitypeedit is required, and the function of displaying a small box in the attribute box Indicating the color of forecolor is also required.
Yes). Let's talk about it in the next article. In addition, the color selection box is [typeconverter (typeof (webcolorconverter)], and enum can be typeconverter
(Typeof (enumconverter )).
In addition, let's take a look at these simple attributes:
[Bindable (true/false)] indicates whether binding data to an attribute makes sense. However, if you set it to false, you can enter an expression in the. aspx file to specify the attribute and the number.
The data binding expression is associated. (About data binding, too)
[Defaultevent ("click")], double-click the control, enter the. CS file, and edit the Click Event code.
[Defaultproperty ("text")], select the control, and propertygrid highlight the text property.
[Editorbrowsable (editorbrowablestate. Always/advanced/never)], whether the Code Editor (not the background code editor, or the aspx file) belongs
Provides intelliisence support for features, methods, and events. The default value is always, and advanced is only used for VB.net. When users choose to view advanced members, intelliisence is provided,
Never does not browse intelliisence information. (I cannot tell where this is used)
[Defaultvalue (propertytype. properdefaultvalue)]. Set the default value of the attribute. Pay attention to the type of the attribute corresponding to the default value, such as the default value of the borderstyle attribute.
You can set [defaultvalue (borderstyle. notset)] instead of [defaultvalue ("notset")].
Next, let's take a look:
The serialized attribute is a string. how to interact with the real attribute type ------ typeconverter
How to change the default control analysis logic ------ persistchildren (false) and controlbuilder to customize Asp.net's analysis of the content in the control label pair