Visual Studio 不会将具有 ReadOnlyAttribute(true) 的属性灰显

发布于 2024-10-10 01:55:15 字数 512 浏览 0 评论 0原文

我知道这很愚蠢,但 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦在深巷 2024-10-17 01:55:15

此行为是设计使然。

要使该属性变灰,请删除设置器。 (或将其设置为私有)

如果您只希望它在设计时为只读,则可以创建一个单独的可写属性并添加 [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.

街道布景 2024-10-17 01:55:15

实现这种行为的唯一方法是不设置 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文