Can I prevent SharpDevelop design view from setting a property's value in InitializeComponent?
I am finding that Design View (DV) is nice, but trying to change the way it automagically injects code into InitializeComponent
is very hard. And sometimes its automagical code breaks the program.
For example, DV automatically sees every single property of my custom UserControl, and then it assigns ev开发者_运维技巧ery single property to some value in InitializeComponent
. But I don't want it to assign values to some of the properties because some of my setters will throw a runtime exception if not used correctly. I could correct InitializeComponent
manually, but anytime I make a change to the design, SharpDevelop will just regenerate the function again.
And there's another case where I have the Default Constructor set the size based upon certain factors, but then InitializeComponent
will immediately set it to another static value.
How can I tell DV to not automagically assign values to certain properties I define?
Unless I misunderstood your scenario, it seems like you're barking up the wrong tree by trying to modify or reconfigure SharpDevelop's behavior. Even if you manage to change it, you won't affect Visual Studio's behavior, and you won't help any of the other consumers of your custom control who don't happen to (and/or don't want to) configure their designer accordingly.
Instead, it seems that you should just mark the properties exposed by your custom control with the [DesignerSerializationVisibility]
attribute. This indicates to the designer exactly how that property's value should be serialized into the InitializeComponent
method.
You have a choice of three different values:
Visible
indicates that the value for the property should be persisted in initialization codeHidden
indicates that the value for the property should not be persisted in initialization codeContent
indicates that initialization code should be generated for each public (not hidden) property of the object assigned to the property
The default value is Visible
, which causes a property's value to be serialized whenever possible.
精彩评论