UserControl properties don't match in designer and InitializeComponent
-
So here's a wierd one.... (sorry for the length, but this needs some 'splainin) I have a
UserControl
consisting of aTextBox
, aLabel
, and aCheckBox
. I have aShowCheckBox
property like so:[Browsable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
EditorBrowsable(EditorBrowsableState.Always),
Bindable(true),
Category("Behavior"),
DefaultValue(true)]
public bool ShowCheckBox
{
get
{
return checkbox.Visible;
}
set
{
checkBox.Visible = value;
}
}(If you see any compile errors, ignore them, I'm typing this from memory. The code I actually have does compile). This
UserControl
is part of the same project as my application. I can place several instances of these controls on my form and theShowCheckBox
property defaults to true, as it should. So far, so good. Now the weird part...through a variety of actions (switching tabs on the form, recompiling or running the application, etc.), suddenly myShowCheckBox
properties all get set to false, so I don't see theCheckBox
in any of myUserControls
in the form's designer! Sure enough, the values are all set to false inInitializeComponent
. I then go back and reset the properties to true in the designer, and I see the property settings disappear fromInitializeComponent
(i.e. the default value is being used). After a little while, it happens again - the values magically get set to false again. I'm thinking this has something to do with theDesignerSerializationVisibility
attribute? Even weirder...usually when something changes inInitializeComponent
or in the designer, the change is automatically reflected in the other location. But when I see the property values set to false inInitializeComponent
, I still see the property set to true in the designer! I probably spent about an hour or so searching Google and CP, and the only help I really found was in setting the attributes I have above. Is this a bug in Visual Studio by any chance? Or is there some other attribute I'm missing? I'm using VS 2005 SP1, C#, Windows XP SP3, all the latest updates. Thanks, Dybs -
So here's a wierd one.... (sorry for the length, but this needs some 'splainin) I have a
UserControl
consisting of aTextBox
, aLabel
, and aCheckBox
. I have aShowCheckBox
property like so:[Browsable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
EditorBrowsable(EditorBrowsableState.Always),
Bindable(true),
Category("Behavior"),
DefaultValue(true)]
public bool ShowCheckBox
{
get
{
return checkbox.Visible;
}
set
{
checkBox.Visible = value;
}
}(If you see any compile errors, ignore them, I'm typing this from memory. The code I actually have does compile). This
UserControl
is part of the same project as my application. I can place several instances of these controls on my form and theShowCheckBox
property defaults to true, as it should. So far, so good. Now the weird part...through a variety of actions (switching tabs on the form, recompiling or running the application, etc.), suddenly myShowCheckBox
properties all get set to false, so I don't see theCheckBox
in any of myUserControls
in the form's designer! Sure enough, the values are all set to false inInitializeComponent
. I then go back and reset the properties to true in the designer, and I see the property settings disappear fromInitializeComponent
(i.e. the default value is being used). After a little while, it happens again - the values magically get set to false again. I'm thinking this has something to do with theDesignerSerializationVisibility
attribute? Even weirder...usually when something changes inInitializeComponent
or in the designer, the change is automatically reflected in the other location. But when I see the property values set to false inInitializeComponent
, I still see the property set to true in the designer! I probably spent about an hour or so searching Google and CP, and the only help I really found was in setting the attributes I have above. Is this a bug in Visual Studio by any chance? Or is there some other attribute I'm missing? I'm using VS 2005 SP1, C#, Windows XP SP3, all the latest updates. Thanks, DybsThis thread seems to be related: http://www.eggheadcafe.com/software/aspnet/32319410/defaultvalue-attribute-on.aspx