[英]Why are certain control properties shown in the Visual Studio designer, and others not?
以我的navigationItem用戶控件:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Uboldi.Helpers;
namespace Uboldi
{
public partial class NavigationItem : UserControl
{
public bool IsSelected { get; set; }
public string Text { get; set; }
public NavigationItem()
{
InitializeComponent();
RefreshDisplay();
}
private void RefreshDisplay()
{
if (IsSelected)
this.BackColor = CustomizationHelper.GetSecondaryColor();
else
this.BackColor = CustomizationHelper.GetPrimaryColor();
}
}
}
在Visual Studio中,我可以看到IsSelected屬性,但看不到Text屬性。
有什么原因嗎?
Text屬性是從UserControl繼承的。 在隱藏的地方,用戶控件沒有任何有意義的文本顯示方式。 您必須再次繼承它,並關閉所有使其隱藏的屬性。 像這樣:
[Browsable(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Bindable(true)]
public override string Text {
get { return base.Text; }
set { base.Text = value; }
}
您需要使用BrowsableAttribute在設計時屬性列表中標記要顯示的屬性。
[Browsable(true)]
public bool Text { get; set; }
猜測是IsSelected屬性是繼承的,並設置了此屬性。 我可能已離開,因為我認為編譯器會警告您,如果是這種情況,您將隱藏繼承的屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.