[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.buildingcontrols

Custom Control: Style Subproperty Changes Not Updating Display at Design-time

Mark Olbert

2/1/2007 4:26:00 AM

I have a custom composite (databound) control with the following property:

[Category("Styles")]
[DefaultValue(null)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("The style for the single character selection links")]
public TableStyle GroupStyle
{
get
{
if( groupStyle == null ) groupStyle = new TableStyle();

return groupStyle;
}

set
{
if( groupStyle != value )
{
groupStyle = value;

RecreateChildControlsIfNecessary();
}
}
}

RecreateChildControlsIfNecessary() basically rebuilds the control hierarchy, applying the style (and yes, I've read I shouldn't
apply styles until rendering do avoid enlarging ViewState, but that's another issue :)).

My problem is this: if, in the VS2005 visual designer I change a subproperty of GroupStyle (say, BackColor) it doesn't update the
display. The set accessor never gets called.

I've read elsewhere that this is a problem with the property editor for styles. The proposed cure is to build my own custom property
editor and force it to always create a new instance of TableStyle when any of its subproperties change.

Which seems like a LOT of work to solve a problem caused by some, ahem, fine programmer at Microsoft forgeting to decorate the
subproperties of the Style object with NotifyParentPropertyAttribute(true) :).

Is there another solution? What is the simplest solution to fix this misbehavior?

- Mark
2 Answers

Mark Olbert

2/1/2007 5:53:00 AM

0

I came up with a solution, but it's pretty ugly. Basically, I walk the subproperty tree of the Style objects in my ControlDesigner,
and put a ValueChange monitor on every single writable subproperty (like I said, this is ugly). Here's the code:

protected override void PreFilterProperties( System.Collections.IDictionary properties )
{
base.PreFilterProperties(properties);

if( properties.Contains("GroupStyle") )
{
PropertyDescriptor propDesc = (PropertyDescriptor) properties["GroupStyle"];
MonitorSubPropChanges(propDesc.GetChildProperties(attrFilter), propDesc.GetValue(Component));
}

if( properties.Contains("LinkStyle") )
{
// attrFilter contains just BrowsableAttribute(true), because I'm only interested in properties I can browse in the
// property grid editor
PropertyDescriptor propDesc = (PropertyDescriptor) properties["LinkStyle"];

MonitorSubPropChanges(propDesc.GetChildProperties(attrFilter), propDesc.GetValue(Component));
}
}

private void MonitorSubPropChanges( PropertyDescriptorCollection props, object propObject )
{
foreach( PropertyDescriptor prop in props )
{
// only monitor read-write properties
if( !prop.IsReadOnly )
prop.AddValueChanged(propObject, new EventHandler(Subprop_Changed));

MonitorSubPropChanges(prop.GetChildProperties(attrFilter), prop.GetValue(propObject));
}
}

private void Subprop_Changed( object sender, EventArgs e )
{
( (BigPicker) Component ).RecreateChildControlsIfNecessary();
}

As the man said, there has >>got<< to be a better way.

Can someone suggest it, please?

- Mark

On Wed, 31 Jan 2007 20:25:49 -0800, Mark Olbert <ChairmanMAO@newsgroups.nospam> wrote:

>I have a custom composite (databound) control with the following property:
>
>[Category("Styles")]
>[DefaultValue(null)]
>[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
>[PersistenceMode(PersistenceMode.InnerProperty)]
>[Description("The style for the single character selection links")]
>public TableStyle GroupStyle
>{
> get
> {
> if( groupStyle == null ) groupStyle = new TableStyle();
>
> return groupStyle;
> }
>
> set
> {
> if( groupStyle != value )
> {
> groupStyle = value;
>
> RecreateChildControlsIfNecessary();
> }
> }
>}
>
>RecreateChildControlsIfNecessary() basically rebuilds the control hierarchy, applying the style (and yes, I've read I shouldn't
>apply styles until rendering do avoid enlarging ViewState, but that's another issue :)).
>
>My problem is this: if, in the VS2005 visual designer I change a subproperty of GroupStyle (say, BackColor) it doesn't update the
>display. The set accessor never gets called.
>
>I've read elsewhere that this is a problem with the property editor for styles. The proposed cure is to build my own custom property
>editor and force it to always create a new instance of TableStyle when any of its subproperties change.
>
>Which seems like a LOT of work to solve a problem caused by some, ahem, fine programmer at Microsoft forgeting to decorate the
>subproperties of the Style object with NotifyParentPropertyAttribute(true) :).
>
>Is there another solution? What is the simplest solution to fix this misbehavior?
>
>- Mark

wawang

2/1/2007 1:22:00 PM

0

Hi Mark,

As I remembered, VS2005 SP1 fixed an issue of the style editor. I cannot
seem to find detailed KB for this fix but the issue is as follows:

1) Drag a Calendar control on webform, open the properties window, expand
property DayHeaderStyle, change its BackColor; notice the Calendar should
reflect the changed backcolor accordingly
2) Right-click on the webform, select "Refresh"
3) Repeat step 1), notice the Calendar will not reflect the changed
backcolor if this is VS2005 without SP1

I'm not sure if this is the same issue you described in your first post.
Anyway, if you haven't installed SP1, you may have a try to see if this is
the same issue that gets fixed. Please let me know the result.

If this is not the case or you've already installed SP1, would you please
create a simpler reproducible custom control project and send it to me? I
can verify the behavior on my side and see if there's a better workaround.
Thanks.


Sincerely,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default....
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/de....
==================================================

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