标签:des style blog http color 使用
正在看ChengKing的文章,感觉是辣么的遥远。
PersistenceMode:指定在 .aspx 或 .ascx 文件中如何以声明方式保持 ASP.NET 服务器控件的属性或事件。
刚看这个的时候虽然每个字都认识,但连在一起就不知道在说什么了,渣渣的人生太悲催。。
<HeaderStyle BackColor="#507CD1" Font-Bold="true" ForeColor="White" />
</asp:GridView>
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem Value="1">男</asp:ListItem>
<asp:ListItem Value="0">女</asp:ListItem>
</asp:ListBox>
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem Value="1">男</asp:ListItem>
<asp:ListItem Value="0">女</asp:ListItem>
</asp:ListBox>
A.首先看Attribute :
using System.ComponentModel;
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Person1
{
private string _name;
[NotifyParentProperty(true)]
public string Name
{
get { return _name; }
set { _name = value; }
}
private int _age;
[NotifyParentProperty(true)]
public int Age
{
get { return _age; }
set { _age = value; }
}
}
1.[TypeConverter(typeof(ExpandableObjectConverter))]
TypeConverter特性指定转换器的类型,ExpandableObjectConverter表示可扩展对象与其他类型的转换器类,该类为系统提供。
依旧不知道在说什么,然后百度了一下,在茫茫字海中看到了ConverterTo,哦,原来是类型转换,比如string --> int,辣么这个
可扩展对象应该是说person下面的Name,Age的值转换为string型。当然这只是我的猜测。。
2.[NotifyParentProperty(true)]
指示当此设计特性应用到的属性的值被修改时将通知其父属性。换言之,如果属性的父属性应该在该属性值被修改时接到通知,则向该属性应用NotifyParentProperty特性。通常使用布尔值进行设置。一般常用于复杂属性,通知转换器更新到父级标记。
这个不是很明白。。。
然后控件代码中加上这么一段
private Person1 ps=null;
[Category()]
[Description()]
[PersistenceMode(PersistenceMode.Attribute)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Person1 person
{
get {
if (ps == null)
ps = new Person1();
return ps;
}
}
3. [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
Ø DesignerSerializationVisibility.Visible
表示代码生成器要对属性本身生成代码。
Ø DesignerSerializationVisibility.Hidden
表示代码生成器不对属性生成代码,即在属性窗口设置的值不会被代码生成器生成到*.aspx或*.ascx文件中。
Ø DesignerSerializationVisibility.Content
表示代码生成器生成复杂属性内容的代码,而不是其本身。比如在上面的People类中,我们实际要操作的数据是People类下面的 Name/Sex/Age属性,即我们在属性窗口中修改了Name/Sex/Age的值后,会仅把这些值通过代码生成器映射到*.aspx或*.axcx页面中。
content应该是这个意思

<cc3:attribute ID="attribute2" runat="server" person-Age="4" person-Name="huihui" />
图片呢,就是在控件属性中给Age和Name赋值,然后在源中就有了person-Age="4" person-Name="huihui",如果 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] 的话,在在控件属性中给Age和Name赋值,然后在源中就没有person-Age="4" person-Name="huihui",源中就是<cc3:attribute ID="attribute2" runat="server"/>。
B:再来InnerProperty
[ToolboxItem(false)]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class ToolColor
{
private Color _backcolor;
[NotifyParentProperty(true)]
public Color Backcolor
{
get { return _backcolor; }
set { _backcolor = value; }
}
private Color _forecolor;
[NotifyParentProperty(true)]
public Color Forecolor
{
get { return _forecolor; }
set { _forecolor = value; }
}
1.[ToolboxItem(false)]
表示不在IDE工具箱的控件集合中显示。很显然这不是一个控件,不能在工具箱集合列表中显示,一般除了主控件之外的其余类都要把ToolBoxItem类元数据特性置为false,否则当使用者拖一个不完整的控件标记到页面上时可能出现控件不能使用的情况。
[DefaultProperty("Text")]
[ToolboxData("<{0}:InnerProperty runat=server></{0}:InnerProperty>")]
[PersistChildren(false)]
[ParseChildren(true)]
public class InnerProperty : WebControl
{
private ToolColor tc = null;
[Description("InnerProperty")]
[Category("")]
[TypeConverter(typeof(ExpandableObjectConverter))]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ToolColor ToolColor
{
get
{
if (tc == null)
tc = new ToolColor();
return tc;
}
}
1.[PersistChildren(false)]和[ParseChildren(true)]
PerseChildren特性指定页面分析器把控件标记中的内容解析为属性还是子控件,该属性值设置为true,则表示解析为属性。PersistChildren指定设计器把控件标记中的内容保存为属性还是子控件,该属性值设置为false,表示保存为属性。
就是这个是属性,不是控件。不设置的话有什么影响还不知道。
这本书看着真心累,,,
PersistenceMode,布布扣,bubuko.com
标签:des style blog http color 使用
原文地址:http://www.cnblogs.com/paidaxing/p/3811408.html