Reputation: 115
Anybody have any ideas how to stop properties being reset on custom user control when it is used?
Similar to question: How can I avoid properties being reset at design-time in tightly bound user controls?
I have tried the solution in the linked question, but they keep on getting reset.
Example property below: Note i have tried to use a simple property but they keep on getting reset to false every time its the containing form is compiled.
[DefaultValue(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Description("Appearance")]
[EditorBrowsable(EditorBrowsableState.Always)]
public bool ImportFilenameShown
{
get { return txtImportFile.Visible; }
set
{
txtImportFile.Visible = value;
lblImportFile.Visible = value;
btnImportMappings.Visible = value;
btnImportFileBrowse.Visible = value;
}
}
Any help would be good. This is driving me crazy.
Upvotes: 2
Views: 479
Reputation: 887797
If one of txtImportFile
's parents are hidden, txtImportFile.Visible
will always return false.
Therefore, the designer will serialize the wrong value.
Instead, you should store the value in a separate backing field
Upvotes: 1