Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bindable attribute doesn't work

I've extended the standard TextBox control to support padding. It works, except that the IDE does not persist the padding into the designer class.

Code:

    [EditorBrowsable(EditorBrowsableState.Always)]
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    [Bindable(true)]
    public new Padding Padding
    {
        get
        {
            return padding;
        }
        set
        {
            padding = value;
            OnPaddingChanged(EventArgs.Empty);
        }
    }

Strangely, if I change the property name to MyPadding or anything else, it suddenly works. What causes this problem?

like image 344
user990827 Avatar asked Sep 10 '26 06:09

user990827


1 Answers

When you shadow a base class property just to change some attributes, don't use own backing field, but base property itself, like this

[EditorBrowsable(EditorBrowsableState.Always)]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Bindable(true)]
public new Padding Padding
{
    get { return base.Padding; }
    set { base.Padding = value; }
}

P.S. While the code above solves the persistence problem, I'm not quite sure what do you mean by "it works" because there must be a some good reason for the corresponding Control property being specifically shadowed in the TextBoxBase class in order to be hidden.

like image 77
Ivan Stoev Avatar answered Sep 11 '26 21:09

Ivan Stoev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!