How do you stop the Designer generating code for public properties on a User Control?

Viewed 12720

How do you stop the designer from auto generating code that sets the value for public properties on a user control?

3 Answers

Use the DesignerSerializationVisibilityAttribute on the properties that you want to hide from the designer serialization and set the parameter to Hidden.

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string Name
{
    get;
    set;
}

Add the following attributes to the property in your control:

[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

A slight change to Erik's answer I am using VS 2013.

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new string Name { 
    get; 
    set; 
}
Related