How to add style properties to a cutomer control

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
 
S

Shimon Sim

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.
 
S

Steven Cheng[MSFT]

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.)
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top