Why does the Custom Control Text property not appear in the properties window?

I have a user control that inherits from UserControl. This is a button, so I'm trying to make the text in the button changeable using the Text property, for example real buttons, instead of calling my own like _Text. I have the following code, but it does not work (i.e., it does not appear in the properties window). Label Name - ContentPresenter

public override string Text
{
    get
    {
        return ContentPresenter.Text;
    }
    set
    {
        ContentPresenter.Text = value;
    }
}
+5
source share
1 answer

UserControl makes significant efforts to hide the Text property. From metadata:

    [Browsable(false)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Bindable(false)]
    public override string Text { get; set; }

You can make this visible by overriding these attributes in your code:

    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    [Bindable(true)]
    public override string Text 
    { 
        get { return ContentPresenter.Text; } 
        set { ContentPresenter.Text = value; } 
    } 

I do not promise that it is enough to make it work, but it probably is.

+12

All Articles