[英]How can I avoid properties being reset at design-time in tightly bound user controls?
我有帶標簽的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',從而導致了問題。
在應用程序中使用緊密綁定的控件和表單時,如何尋求一種更好的設計模式方法來避免此類行為?
我有同樣的問題。
嘗試這個:
[Category("Appearance")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override string Text
{
get { return uxLabel.Text; }
set { uxLabel.Text = value; }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.