我可以阻止 SharpDevelop 设计视图在 InitializeComponent 中设置属性值吗?

发布于 2024-10-13 02:24:37 字数 434 浏览 5 评论 0原文

我发现设计视图 (DV) 很好,但尝试改变它自动将代码注入 InitializeComponent 的方式非常困难。有时它的自动代码会破坏程序。

例如,DV 自动查看我的自定义 UserControl 的每个属性,然后将每个属性分配给 InitializeComponent 中的某个值。但我不希望它为某些属性赋值,因为如果使用不正确,我的一些设置器将引发运行时异常。我可以手动更正 InitializeComponent,但每当我对设计进行更改时,SharpDevelop 都会再次重新生成该函数。

还有另一种情况,我让默认构造函数根据某些因素设置大小,但随后 InitializeComponent 会立即将其设置为另一个静态值。

我如何告诉 DV 自动为我定义的某些属性赋值?

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 every 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剩余の解释 2024-10-20 02:24:37

除非我误解了您的情况,否则您似乎通过尝试修改或重新配置 SharpDevelop 的行为而找错了方向。即使您设法更改它,也不会影响 Visual Studio 的行为,并且您不会帮助您的自定义控件的任何其他使用者,因为他们不碰巧(和/或不想)配置其控件设计师相应地。

相反,您似乎应该只使用 [DesignerSerializationVisibility] 属性。这向设计者准确指示该属性的值应如何序列化到 InitializeComponent 方法中。

您可以选择三个不同的值

  • 可见指示该属性的值应保留在初始化代码中
  • 隐藏表示该属性的值不应保留在初始化代码中
  • Content 表示初始化代码应该为分配给属性的对象的每个公共(非隐藏)属性生成。

默认值为 Visible,这会导致属性的值尽可能被序列化。

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 code
  • Hidden indicates that the value for the property should not be persisted in initialization code
  • Content 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文