Visual Studio 不会将具有 ReadOnlyAttribute(true) 的属性灰显
我知道这很愚蠢,但 Visual Studio (2010) 不会将我标记为 ReadOnlyAttribute 的属性变灰,我无法编辑它们的值(如果我尝试这样做,只需返回到以前的值),但它们不会变灰出来,我认为使用编辑器时真的很无聊
是否有我忘记的选项或属性?
感谢您的帮助
示例 1:
/// <summary>
/// Inform if the LcdDisplay has been already initiated
/// </summary>
[Description("Inform if the LcdDisplay has been already initiated")]
[DefaultValue(false)]
[ReadOnly(true)]
public bool Initialized { get; private set; }
初始化未灰显
I know it's stupid but visual studio (2010) doesn't gray out my properties tagged with ReadOnlyAttribute, I can't edit their values (if I try to do it, simply return to the previous value), but they aren't grayed out, I think it's really boring this when using the editor
Is there an option or an attribute that I'm forgetting?
Thanks for any help
Example 1:
/// <summary>
/// Inform if the LcdDisplay has been already initiated
/// </summary>
[Description("Inform if the LcdDisplay has been already initiated")]
[DefaultValue(false)]
[ReadOnly(true)]
public bool Initialized { get; private set; }
Initialized is not grayed out
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此行为是设计使然。
要使该属性变灰,请删除设置器。 (或将其设置为私有)
如果您只希望它在设计时为只读,则可以创建一个单独的可写属性并添加
[Browsable(false)]
以将其从属性网格中隐藏。This behavior is by design.
To make the property grayed out, remove the setter. (or make it private)
If you only want it to be readonly at designtime, you can make a separate writable property and add
[Browsable(false)]
to hide it from the property grid.实现这种行为的唯一方法是不设置 setter,也许是因为设计者将私有字段视为他可以访问的内容,因此不会将其灰显。
The only way to have this behaviour is not to have a setter, maybe because the designer see the private field as something that he can access to so it doesn't gray out it.