Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Bug in .Net user controls & Designer serialization?

Options
  • 09-05-2007 9:48pm
    #1
    Registered Users Posts: 246 ✭✭


    Back in the day when I created usercontrols in VB6 we all used a PropertyBag into which we could read/write values and which provided us with spiffy events so we could know when to read or write values.

    I'm using C# now and something funny happened. I have this new control that I'm writting. I have an instance of it in the designer window (on a form) and I change its caption in the property window to "My silly caption". Normally as soon as you set a property VisualStudio adds a line to the Form.designer.cs for whatever form or container hosts the instance of the control. That way when the runtime instance of the control is instantiated it just gets its values from the designer.cs.

    Thank you Microsoft for making life easy.... in fact so easy some of my colleagues had created controls and never knew abouthe the mechanism behind it.

    I decided over the long weekend (I have no life) to do some work on it at home. Same code as in work, same Visual Studio and when I hit F5 all the instances had "Caption" as their caption... which of course what the string is in the usercontrol itself.

    Scratched my head a bit and thought "huhhh?" Checked same code on my work machine today and it works as expected. But the line was not added to the Form.designer.cs on my home machine.
    So I searched quite a bit... as you'd expect any searches for PropertyBags gives tonnes of ASP topics which is not what I'm after.
    But I did find something in MSDN:

    http://msdn2.microsoft.com/en-us/library/ms171731(vs.80).aspx

    I added:

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    Directly above the property I wanted to serialize and hey presto it works again... but only for that property. My understanding was that this specific serialization was for complex types... not simple data types.

    So I'm guessing that there is either a switch that turns off the global persistance of values from design to runtime (allowing you to do it yourself on a case per case basis) or this is a bug.

    Anybody come across anything remotely like this, or have I been too long in front of a screen?


Advertisement