繁体   English   中英

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

[英]Why are certain control properties shown in the Visual Studio designer, and others not?

以我的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属性。 在此处输入图片说明

有什么原因吗?

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

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

您需要使用BrowsableAttribute在设计时属性列表中标记要显示的属性。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM