How can I avoid properties being reset at design-time in tightly bound user controls?

Posted by David Anderson on Stack Overflow See other posts from Stack Overflow or by David Anderson
Published on 2009-06-28T23:56:12Z Indexed on 2010/03/18 13:21 UTC
Read the original article Hit count: 349

I have UserControl 'A' with a label, and this property:

    /// <summary>
    /// Gets or Sets the text of the control
    /// </summary>
    [
        Browsable(true),
        EditorBrowsable(EditorBrowsableState.Always),
        Category("Appearance")
    ]
    public override string Text {
        get {
            return uxLabel.Text;
        }
        set {
            uxLabel.Text = value;
        }
    }

I then have UserControl 'B' which has UserControl 'A' on it, and I set the Text Property to "My Example Label" in the designer. Then, I have my MainForm, which has UserControl 'B' on it.

Each time I do a build or run, the Text property of UserControl 'A' is reset to its default value. I suppose this is because since I am doing a rebuild, it rebuilds both UserControl 'A' and 'B', thus causing the problem.

How can I go about a better approach to design pattern to avoid this type of behavior when working with tightly bound controls and forms in a application?

© Stack Overflow or respective owner

Related posts about c#

Related posts about usercontrol