How to add style properties to a cutomer control

  • Thread starter Thread starter Shimon Sim
  • Start date Start date
S

Shimon Sim

I need to add few style properties to my custom control.

The properties I added look like this.

private Style titleStyle = new Style();

[Browsable(true),

DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

public Style TitleStyle

{

get {return titleStyle;}

set {titleStyle =value;}

}

The problem is that Properties panel in design view doesn't allow me do
anything with this property.

What did I miss?

Thanks
 
I think I figure it out.
I added new class
public class MyStyle:Style
{}
Changed Style to MyStyle and everything work.But I don't understand it.
 
Hi Shimon,

As for the Style property, since Style class it self is a complex reference
type which contains nested properties, generally, we only need to define a
get accessor for it, and all the modification on it is performed on its sub
properties rather than the style instance itself. So we can just define the
Style property like below:

======================
[Browsable(true),

DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Style MyStyle
{
get
{
if (_mystyle == null)
{
_mystyle = new Style(this.ViewState);
}

return _mystyle;
}
}

===============================

This works well on my local test environment.

Hope also helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Check out my code, it support both page intellesense and property view.

[DefaultValue((string)null),
Description("Item style"),
PersistenceMode(PersistenceMode.InnerProperty),
Category("Styles"),
NotifyParentProperty(true),

DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public TableItemStyle ItemStyle
{
get
{
if (this._itemStyle == null)
{
this._itemStyle = new TableItemStyle();
if (base.IsTrackingViewState)
{
IStateManager ism;
ism = (IStateManager)_itemStyle;
ism.TrackViewState();
return _itemStyle;
}
}
return this._itemStyle;
}
}

Shimon Sim said:
I think I figure it out.
I added new class
public class MyStyle:Style
{}
Changed Style to MyStyle and everything work.But I don't understand it.


Shimon Sim said:
I need to add few style properties to my custom control.

The properties I added look like this.

private Style titleStyle = new Style();

[Browsable(true),

DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

public Style TitleStyle

{

get {return titleStyle;}

set {titleStyle =value;}

}

The problem is that Properties panel in design view doesn't allow me do
anything with this property.

What did I miss?

Thanks
 
Back
Top