为什么某些控件属性显示在 Visual Studio 设计器中,而其他属性则不显示?
以我的 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 属性。
有什么原因吗?
Take my navigationItem usercontrol:
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();
}
}
}
In Visual Studio I can see the IsSelected property, but not the Text property.
Any reason why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Text 属性继承自 UserControl。在隐藏的地方,用户控件无法以有意义的方式显示文本。您必须再次继承它并关闭所有使其隐藏的属性。像这样:
The Text property is inherited from UserControl. Where it is hidden, a user control has no meaningful way of of showing text. You have to inherit it again and turn all the attributes off that make it hidden. Like this:
您需要使用 可浏览属性。
据猜测,IsSelected 属性被继承,并设置了此属性。我可能会离开,因为我认为编译器会警告您,如果是这种情况,您正在隐藏继承的属性。
You need to mark the properties you want visible in the design time properties list with a BrowsableAttribute.
At a guess, the IsSelected property was inherited, and had this attribute set. I'm probably off, because I think the compiler would warn you that you were shadowing an inherited property if this was the case.