为什么某些控件属性显示在 Visual Studio 设计器中,而其他属性则不显示?

发布于 2024-10-14 02:05:58 字数 955 浏览 11 评论 0原文

以我的 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.
enter image description here

Any reason why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

踏月而来 2024-10-21 02:05:58

Text 属性继承自 UserControl。在隐藏的地方,用户控件无法以有意义的方式显示文本。您必须再次继承它并关闭所有使其隐藏的属性。像这样:

    [Browsable(true)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [Bindable(true)]
    public override string Text {
        get { return base.Text; }
        set { base.Text = value; }
    }

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:

    [Browsable(true)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [Bindable(true)]
    public override string Text {
        get { return base.Text; }
        set { base.Text = value; }
    }
雨轻弹 2024-10-21 02:05:58

您需要使用 可浏览属性

[Browsable(true)]
public bool Text { get; set; } 

据猜测,IsSelected 属性被继承,并设置了此属性。我可能会离开,因为我认为编译器会警告您,如果是这种情况,您正在隐藏继承的属性。

You need to mark the properties you want visible in the design time properties list with a BrowsableAttribute.

[Browsable(true)]
public bool Text { get; set; } 

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.

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