on the article, and we explore the relationship between the properties and the aspx file in HTML style tags and text, missing two things:
1 EnCodedInnerDefaultProperty and InnerDefaultProperty difference, in use , there may be some friends about this not very clear,
EncodedInnerDefaultProperty property is not allowed to control the contents of the object, for example, declares DataList Text property EncodedInnerDefaultProperty that
does not allow you to "<table ......> ..... </> "and the like containing HTML tags (exactly solvable noted object) content. And declared
the Items property of the DropDownList InnerDefaultProperty you can write <asp: datalist value = "1such content.
2, if a property should not be in control in the aspx file, how to do it?
These we can that the Attribute:
DesignerSerilizationVisibility (DesignerSerializationVisibility.Hidden)
Well, we turn today to the question: attributes and properties pane
believe that most programmers in most cases is to use the properties pane to set the properties of a control object, Therefore, the properties pane also control design essential.
In the Properties pane, said that, we need to look at PropertyGrid, PropertyGrid is located under the System.Windows.Forms.dll controls, VS.net and other IDE
Tool is to use it to provide display properties, operating functions, we may and usually has no concept of this control, though perhaps you are using the functionality it provides every day.
If you want a better description of it, you can build a Winform project, add the control to VS.net toolbox, and then pull to form a look at it, this work
with our programming is generally less than it , but when you want to provide custom-designed for the control (such as DataGrid property editor), using it is a good
idea to something more (for various designers and PropertyGrid, I will in the future design of the control design when the feature articles and then tell).
There are many different forms PropertyGrid when displaying the control's properties,
for example: Button Font property, ProperyGrid it appears as a deployable, folded set of attributes, first Font type attribute is a complex class
(FontInfo), it has a lot of sub-attributes, then, you want to apply attribute we mentioned above:
the DesignerSerializationVisibility (DesignerSerializationVisibility.Content)
which represents the serialization code generator sub-attribute instead of its own, how to understand it? That Font property of the Button control's child Bold and Underline attributes
will be serialized as (Font-Underline = "True" Font-Bold = "True"), rather than the Style property into the same mess sequence (style = " the INDEX-the Z: 101;
the LEFT: 224px; the POSITION: Absolute; the TOP: 240px "), and under normal circumstances, we will give more than one such property and is provided on the other of attribute values :
[NotifyParentProperty (true)] (System.ComponentModel.NotifyParentPropertyAttribute , the default is false) It is to signal
PropertyGrid sub-attributes from the parent to notify a change.
The default value is DesignerSerializationVisibility DesignerSerializationVisibility.Visible ; and the above-mentioned Hidden value makes the corresponding attribute is not a sequence
of, for example, you do a SQLServerConnection control, you will not want to provide to the user serialization ConnectPassword property, write it in. Gong aspx file
can. At the same time, set the Hidden attribute will not appear in the PropertyGrid.
So if I want to just a property is not displayed in the PropertyGrid, but may be provided and the sequence values in the .aspx file, then you can not use the above-described Attribute
with [Browsable (false)], the default Attribute value is true, full name is System.ComponentModel.BrowsableAttribute .
Then it, programmers generally work is more structured, like me :), then we will want to control the placement of the various properties of different categories in the PropertyGrid to
do this, it is easy, as long as you attribute declaration above note on the following Attribute:
[Category ( "Behavior")] (System.ComponentModel.CategoryAttibute, its default value is "Default"), this sentence means that this property is classified as acts of
this section, please note that the image data, appearance, behavior , miscellaneous (Default) and other categories, you do not have to write [category ( "behavior")] and write [category ( "behavior")],
VS.net will automatically do the localization work.
Then, you might want to write a few attribute Comment, you can use the Attribute:
[the Description ( "Today you write control yet")] (System.ComponentModel. DescriptionAttribute , this property may you also want to be localized, so comments see
people that were so, hell that nonsense, it is also possible, but not so automatic Category, to do more, with respect to localized control, we discuss later)
now, let's look at a few different styles of support PropertyGrid to edit the properties offered:
text box type, drop-down list, pop-up window style.
Text Box is the default, such as Button's Text;
drop-down list type, for example, I wrote RockToControl property RockUControl control, and the properties of selected objects verified Validator controls series;
pop-up window type, such as color properties, provide a form to We choose.
The first is the default, we do not control, we look at the drop-down, to achieve this effect, use the Attribute like a bee with horses and cattle are not the same:
[TypeConverter (typeof (YourCustomConverter))]
As RockToControl attribute my RockUControl control
[Category( " Behavior " )]
[DefaultValue( "" )]
[TypeConverter( typeof (THINControls.WebControls.Designer.FormControlsConverter))]
[Description( " 要滚动的对象。 " )]
public string RockToControl
{
get
{
object o = ViewState["RockToControl"];
return (o==null)?"":o.ToString();
}
set
{
ViewState["RockToControl"] = value;
}
}
再看FormControlsConverter类(请认真查看我加的注释)
{
public FormControlsConverter()
{
}
//这一个override说明要用下拉列表编辑属性
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
//这个override返回下拉列表项,有朋友曾问怎么实现拿出当前页面的控件,以下就是我摸索出来的代码。
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 ture的话只能选,return flase可选可填
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
}
弹出窗体的比较麻烦(要用到UITypeEdit,还有要实现ForeColor那种选好颜色会显示一个小方框在属性框中表示颜色的功能也
是),我们在下一篇文章中再谈。另外,颜色选择框是[TypeConverter(typeof(WebColorConverter)],Enum可用TypeConverter
(typeof(EnumConverter))。
此外,我们还要关注一下这几个比较简单的Attribute:
[Bindable(true/false)],绑定数据到属性是否有意义,不过你设为false,用户一样可以在.aspx文件中输入表达式要把属性和一个数
据绑定表达式关联起来。(关于数据绑定,也是后话)
[DefaultEvent("Click")],双击控件,进入.cs文件,并开始编辑Click事件代码。
[DefaultProperty("Text")],选择控件,PropertyGrid把Text属性高亮显示。
[EditorBrowsable(EditorBrowableState.Always/Advanced/Never)],代码编辑器(不是后台代码编辑器,是指aspx文件的)是否为属
性、方法、事件提供IntelliSence支持,Default为Always,Advanced只用于VB.net,在用户选择查看高级成员时提供IntelliSence,
Never was not browse IntelliSence information. (I could not give an example of this where used)
[the DefaultValue (PropertyType.ProperDefaultValue)], set the default value of the attribute, the type of note corresponding to the default value of the attribute type, such as the default BorderStyle property
values you can set [the DefaultValue (BorderStyle .NotSet)] and not to write became a [DefaultValue ( "NotSet")]
The next article, we look at:
serialized property is a string, and how to interact with the real property type ------ TypeConverter
how to change the default control logic analysis ------ PersistChildren (false ) and analysis of ASP.net ControlBuilder to customize content control tags in the
property editor
......
Reproduced in: https: //www.cnblogs.com/think/archive/2005/05/16/156158.html