我正在尝试将一些字段添加到我正在制作的自定义 UserControl
中。我有一些字段,我希望它们在 Visual Studio
的 Properties
窗口中可见。我尝试使用下面的标志,但我没有在设计器中看到该字段,即使在编译之后也是如此。
我应该如何正确执行此操作?
public partial class TosChartControl: UserControl
{
#region PUBLIC FIELDS
[Browsable(true)] //Added this but still does not show up
[Category("Data")]
[DefaultValue(0)]
[Description("ID of the Sensor Node")]
public int NodeId { get; set; }
#endregion
public TosChartControl()
{
InitializeComponent();
}
}
我确实清理并重建了解决方案和项目,但我仍然无法在“属性”窗口中看到该字段。甚至重新启动 Visualstudio 也无济于事。
最佳答案
更新:您的公共(public)属性只有在设计器中的另一个控件中时才在设计器中可见。事实证明,您不需要 添加此属性,默认情况下属性在设计器中可见。据我了解,当它位于另一个组件的设计 View 中时,将创建用户控件的实例并显示属性。抱歉一开始误导大家了,我觉得有必要加上。
试试这个属性:
[Browsable(true)]
http://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute.aspx
关于c# - 在设计器中显示 UserControl 的公共(public)字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17447684/