如何避免在设计时紧密绑定的用户控件中重置属性?
我有带有标签的 UserControl 'A' 和此属性:
/// <summary>
/// Gets or Sets the text of the control
/// </summary>
[
Browsable(true),
EditorBrowsable(EditorBrowsableState.Always),
Category("Appearance")
]
public override string Text {
get {
return uxLabel.Text;
}
set {
uxLabel.Text = value;
}
}
然后我有 UserControl 'B',其上有 UserControl 'A',并且我在设计器中将 Text 属性设置为“我的示例标签”。 然后,我有我的 MainForm,上面有 UserControl 'B'。
每次我进行构建或运行时,UserControl“A”的 Text 属性都会重置为其默认值。 我想这是因为由于我正在进行重建,它重建了 UserControl 'A' 和 'B',从而导致了问题。
在应用程序中使用紧密绑定的控件和表单时,如何采用更好的设计模式方法来避免这种类型的行为?
I have UserControl 'A' with a label, and this property:
/// <summary>
/// Gets or Sets the text of the control
/// </summary>
[
Browsable(true),
EditorBrowsable(EditorBrowsableState.Always),
Category("Appearance")
]
public override string Text {
get {
return uxLabel.Text;
}
set {
uxLabel.Text = value;
}
}
I then have UserControl 'B' which has UserControl 'A' on it, and I set the Text Property to "My Example Label" in the designer. Then, I have my MainForm, which has UserControl 'B' on it.
Each time I do a build or run, the Text property of UserControl 'A' is reset to its default value. I suppose this is because since I am doing a rebuild, it rebuilds both UserControl 'A' and 'B', thus causing the problem.
How can I go about a better approach to design pattern to avoid this type of behavior when working with tightly bound controls and forms in a application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有同样的问题。
尝试这个:
I had the same problem.
Try this: