Web Custom Control, Property Nesting

topic posted Sun, May 15, 2005 - 12:09 PM by  Elfie
Share/Save/Bookmark
Advertisement
Alright, I'm REALLY close to having this working the way I want, but something is missing. I've got a web custom control that has several different pieces, which may each have their own font info... in the designer, I want each section for the different font settings to be expandable, so I created a "TextFormatting" class:

[TypeConverter(typeof(ExpandableObjectConverter)),
ParseChildren()]
public class TextFormatting
...

The properties that use the class are defined as:

[Bindable(true),
Category("Appearance"),
Description("...")]
public TextFormatting PropertyName
...

This class contains Font, ForeColor, and CssClass. The Font property is designed as:

[Description("The font used for text within the control.")]
[NotifyParentProperty(true)]
public FontInfo Font
...

ForeColor and CssClass are defined similarly.

Now... this ALMOST works. When I put the control on an aspx page and go to the designer properties, I get nice expandable sections for "AlbumStatistics" and "AlbumTitles" which are both TextFormatting properties. These break out with Font, ForeColor, and CssClass settings. Yay! If I set ForeColor or CssClass, the go to html view, I get attributes like AlbumTitles-CssClass="NormalStyle" which is just dandy. While in HTML view, I can manually add the attribute AlbumTitles-Font-Italic="True" and when I go back to the designer, the "AlbumTitles" section is italicized and the setting in the properties window for AlbumTitles/Font/Italic is indeed set to True!

Just one more thing to test, right? What if I change a Font sub-setting like Bold from within the designer? It SHOULD place a setting in the HTML view along the lines of AlbumTitles-Font-Bold="True" but you know what? it doesn't... it doesn't do anything. I can NOT get that property to change from the designer. Sure, it changes the control visually, but it doesn't actually change the HTML... ANY ideas as to what I'm missing here?
posted by:
Elfie
Maryland
Advertisement
Advertisement
  • Re: Web Custom Control, Property Nesting

    Sun, May 15, 2005 - 12:30 PM
    Addendum: okay, actually... now CssClass and ForeColor aren't working either... I really thought they were working a minute ago, but perhaps I imagined it... I CAN get them to appear as inner-properties by setting "[PersistenceMode(PersistenceMode.InnerProperty)]" on the TextFormatting properties (not class) and on the Font property within TextFormatting. This results in something like the following:

    <pa:photoalbumlist id="PhotoAlbumList1" runat="server">
    <AlbumTitles ForeColor="192, 64, 0" CssClass="">
    <Font Bold="True"></Font>
    </AlbumTitles>
    </pa:photoalbumlist>

    this WORKS, but I would much MUCH rather have them as attributes. Seetting PersistenceMode.Attribute doesn't seem to be working...
    • Re: Web Custom Control, Property Nesting

      Sun, May 15, 2005 - 12:41 PM
      Conclusion: hah! figured it out... sorry to have bothered you with all this. I was racking my brain all day over it and then as I was writing it all out to you folks, it just worked itself out.... if you're curious, the answer was to put [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] on all of the expandable properties that I wanted to show up in the HTML.

      ... that was fun :)