Style
[PersistenceMode(PersistenceMode.Attribute)]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
namespace WebApplication40
{
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Style
{
//private Color _BackColor;
//[NotifyParentProperty(true)]
//public Color BackColor
//{
// get { return _BackColor; }
// set { _BackColor = value; }
//}
private string _X;
private string _Y;
[NotifyParentProperty(true), DefaultValue("")]
public string X
{
get { return _X; }
set { _X = value; }
}
[NotifyParentProperty(true), DefaultValue("")]
public string Y
{
get { return _Y; }
set { _Y = value; }
}
public Style()
: this(String.Empty, String.Empty)
{
}
public Style(string X, string Y)
{
this._X = X;
this._Y = Y;
}
public override string ToString()
{
return "";
}
public virtual string ToString(CultureInfo culture)
{
return TypeDescriptor.GetConverter(typeof(Style)).ConvertToString(null, culture, this);
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
namespace WebApplication40
{
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Style
{
//private Color _BackColor;
//[NotifyParentProperty(true)]
//public Color BackColor
//{
// get { return _BackColor; }
// set { _BackColor = value; }
//}
private string _X;
private string _Y;
[NotifyParentProperty(true), DefaultValue("")]
public string X
{
get { return _X; }
set { _X = value; }
}
[NotifyParentProperty(true), DefaultValue("")]
public string Y
{
get { return _Y; }
set { _Y = value; }
}
public Style()
: this(String.Empty, String.Empty)
{
}
public Style(string X, string Y)
{
this._X = X;
this._Y = Y;
}
public override string ToString()
{
return "";
}
public virtual string ToString(CultureInfo culture)
{
return TypeDescriptor.GetConverter(typeof(Style)).ConvertToString(null, culture, this);
}
}
}
就是这里 PersistenceMode要选择Attribute
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
这里DesignerSerializationVisibility 要选择Content 就能实现我的效果了
myTextBox
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication40
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:myTextBox runat=server></{0}:myTextBox>")]
public class myTextBox : TextBox
{
private Style _Style;
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public override string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["Text"] = value;
}
}
[PersistenceMode(PersistenceMode.Attribute)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[NotifyParentProperty(true)]
[Category("复杂属性")]
[Description("复杂属性——内部嵌套形式")]
public Style BackColorStyle
{
get
{
if (_Style == null)
{
_Style = new Style();
}
return _Style;
}
}
protected override void RenderContents(HtmlTextWriter output)
{
output.Write(Text);
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication40
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:myTextBox runat=server></{0}:myTextBox>")]
public class myTextBox : TextBox
{
private Style _Style;
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public override string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["Text"] = value;
}
}
[PersistenceMode(PersistenceMode.Attribute)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[NotifyParentProperty(true)]
[Category("复杂属性")]
[Description("复杂属性——内部嵌套形式")]
public Style BackColorStyle
{
get
{
if (_Style == null)
{
_Style = new Style();
}
return _Style;
}
}
protected override void RenderContents(HtmlTextWriter output)
{
output.Write(Text);
}
}
}
From:锋火燎皇